I have the order function, in which it shows the items related to said order, what I want to do is, paginate only the items within the order.
public function order()
{
$orderId = request()->get('id', 0);
$order = null;
$order = OrderItem::with(['items'])->find($orderId);
if ($orderId != 0) {
if ($order == null) {
return Inertia::render('IDashboard/utils/IError');
}
}
return Inertia::render(
'Orders/IData',
['order' => $order]
);
}
I have tried with:
public function order()
{
$orderId = request()->get('id', 0);
$order = null;
$order = OrderItem::find($orderId);
if ($orderId != 0) {
if ($order == null) {
return Inertia::render('IDashboard/utils/IError');
}
}
$items = Item::where('order_item_id', $orderId)->paginate(10);
return Inertia::render(
'Orders/IData',
['order' => $order, 'itemsList' => $items]
);
}
But the problem in this other case is that, when doing the pagination in the Vue component, and hitting page 2, it does not show me any information. Child component.
props: {
is: Function,
order: Object,
orderItems: Object,
itemsList: Object,
},
<IItemCalculate
v-for="(
item, index
) in orderItems"
:order="order"
:item="item"
:key="index"/>
<IPagination :links="itemsList.links" /> //general pagination component:
the path i am using is:
Route::get('/order', 'App\Http\Controllers\ItemController@order')->name('order');
Errores.
The error is that, at the moment of giving page 2, or next, the content is not displayed, or The error is that, at the moment of giving page 2, or next, the content is not displayed, or when I do the pagination within the relationship, that is $items = $order->items()->paginate(10)
, throws the error, member function items() on null, also when going to the next page.
Thank you very much, I'm up to date.
You can solve this by including the order_id
in the path instead of query like : 127.0.0.1:8000/order/1
then modify the controller a little.
Route::get('order/{id}', [...])->name('orders');
Since you want to render different page in case the order
do not exists you can skip the Route-Model Binding
.
public function order($id) {
$order = Order::query()->find($id);
if(is_null($order)) {
return Inertia::render('IDashboard/utils/IError');
}
$items = Item::query()
->where('order_item_id', $order->id)
->paginate(10);
return Inertia::render('Orders/IData', compact('order','items'));
}
If you really want to include the order_id
as a query string you can look into this. I didn't try it yet.