Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function vendors(): Collection
- {
- return $this->belongsToMany(Vendor::class);
- }
- public function index(): Response
- {
- $products = Product::with('vendors')->get();
- if (!$products) {
- $productsNotFoundMessage = 'Nie znaleziono produktów';
- return view('products.index', compact('productsNotFoundMessage'));
- }
- return view('products.index', compact('products', 'productWithoutSuppliers'));
- }
- view:
- {{ productstNotFoundMessage }} // Not sure if it will interpolate it as ''
- @foreach($product->vendors as $vendor)
- {{ $vendor->name ?: 'Nie znaleziono dostawców dla tego produktu' }}
- @endforeach
Add Comment
Please, Sign In to add comment