So I have defined relationship between OrderProduct.php
and 'Product.php' models like this:
OrderProduct.php
:
public function product()
{
return $this->belongsTo('App\Product');
}
Product.php
public function order()
{
return $this->belongsTo('App\OrderProduct');
}
OrderController
function
public function orderShow($id)
{
//$order = Order::where('id', $id)->first();
$products = OrderProduct::where('id', 32)->first();
return view('admin.orders.show', compact('order', 'products'));
}
When I do this foreach:
@foreach($products as $product)
<?php dd($product) ?>
@endforeach
I get Invalid argument supplied for foreach()
How to fix this ?