I am working on a Laravel 5.8 project which is an Online Store. and in this project, I wanted to add "Printing Order Factors" feature for Admins.
So I have made a form like this:
<form method="POST" action="{{ route('orders.newprint') }}">
@csrf
@forelse($orders as $order)
<tr>
<td><input class="form-check-input" name="orderCheck[]" type="checkbox" value="{{ $order->ord_id }}"> </td>
<td>{{ $order->ord_id }}</td>
<td>{{ $order->status_label }}</td>
<td>{{ $order->customer_name }}</td>
<td>{{ $order->ord_total }}</td>
</tr>
@empty
<td colspan="7" class="text-center">No order to show</td>
@endforelse
</form>
So basically admins can select multiple orders like this:
And I'm trying to send order ids as an array:
<input class="form-check-input" name="orderCheck[]" type="checkbox" value="{{ $order->ord_id }}">
Then at the Controller I have added this:
if(!empty($request->input('orderCheck'))) {
$args = [];
$orders = $request->input('orderCheck');
foreach ($orders as $ord) {
$order = Order::find($ord);
$args[] = [
'order' => $order,
'address' => $order->order_address->first(),
'details' => $order->orderDetail,
'sendType' => $order->productSubmit,
'coupons' => $this->cartController->computeDiscountForOutRequests($order->ord_object_id, $order->ord_creator_id),
'user' => User::query()->find($order->ord_creator_id)
];
}
view('admin.shop.orders.printfactors', compact('args'));
}else{
return back();
}
And finally at the Blade printfactors.blade.php
:
@foreach($args as $arg)
...
@forelse($arg['details'] as $detail)
{{ $detail->product->prd_name }}
@empty
@endforelse
@endforeach
But I get this error:
Trying to get property 'product' of non-object (View: printfactors.blade.php)
So how to solve this?
I would really appreciate any idea or suggestion from you guys about this...
Thanks.
Here is the result of dd($detail)
: