This will not work, as you cannot identify the individual product, with its parent orderproduct, unless you specify that within the table, which shouldnt be done as products are used globally in the application.
public function orderproduct() {
return $this->belongsTo('App\OrderProduct');
}
Anyway, I believe the code below should work for displaying the order.
First rename this from orderproduct to OrderProducts.
public function orderproduct() {
return $this->hasMany('App\OrderProduct');
}
Second rename this from product to Product, its just cosmetic but makes it easy to see what is a relation, and what is a field
public function product() {
return $this->hasMany('App\Product');
}
After that is done, you should be able to list the products using the code below.
public function viewOrder($orderid) {
$order = Order::findOrFail($orderid);
if ($order->customer_id != Auth::user()->id) {
return abort(401);
}
return view('orderview', ['order' => $order]);
}
In the view you add this
<table style="width:100%">
<tr>
<th>Product</th>
<th>Desc</th>
<th>Quantity</th>
</tr>
@foreach ($order->OrderProducts as $orderProduct)
<tr>
<td>{{ $orderProduct->Product->name }}</td>
<td>{{ $orderProduct->Product->desc }}</td>
<td>{{ $orderProduct->quantity }}</td>
</tr>
@endforeach
</table>


