Guest User

Untitled

a guest
Jan 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public function vendors(): Collection
  2. {
  3. return $this->belongsToMany(Vendor::class);
  4. }
  5.  
  6. public function index(): Response
  7. {
  8. $products = Product::with('vendors')->get();
  9.  
  10. if (!$products) {
  11. $productsNotFoundMessage = 'Nie znaleziono produktów';
  12.  
  13. return view('products.index', compact('productsNotFoundMessage'));
  14. }
  15.  
  16. return view('products.index', compact('products', 'productWithoutSuppliers'));
  17. }
  18.  
  19.  
  20. view:
  21.  
  22. {{ productstNotFoundMessage }} // Not sure if it will interpolate it as ''
  23.  
  24. @foreach($product->vendors as $vendor)
  25. {{ $vendor->name ?: 'Nie znaleziono dostawców dla tego produktu' }}
  26. @endforeach
Add Comment
Please, Sign In to add comment