I持ってコントローラーに次の関数:Laravel 5.
public function getProduct()
{
return Product::join('shopping_list_items', 'products.id', '=', 'shopping_list_items.product_id')
->join('shop_lists', 'shop_lists.id', '=', 'shopping_list_items.shopping_list_id')
->select('products.product_name', 'products.id')
->where('shop_lists.id', $this->id);
}
ビューのこのコードは完璧に動作し、製品名を示しています。
{{$shoppinglists->getProduct()->first()->product_name}}
をしかし、私はすることができます」このようにループする:
@foreach($shoppinglists->getProduct() as $sh)
{{$sh->product_name}}<br>
@endforeach
エラーは表示されませんが、
を使用し、追加 - >(GET); – Carlos
ありがとう! get()の有無にかかわらずオブジェクトの違いを説明できますか? –
違いは、それがなければ、それは事ではないということです。 - > get();クエリを実行してオブジェクトを返すように指示します。 – Lynne