Created
January 13, 2018 18:12
-
-
Save tulik/54b234352af9a6aa8abe502718d1c339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment