@and94es so, 2 possibilities:
- $request['pagination'] is null
- $pagination is null
just dd it
$pagination = $request->query('pagination');
dd($request['pagination'], $pagination);
I'm using Laravel witch Vuejs, present the following condition which goes through the categories, the daughter categories and the products. The conditional works, but when displaying the data of the query it gives me the error of: Trying to access array offset on value of type null
The error gives me in: ->paginate($request['pagination']['per_page'], ['*'], 'page', $pagination['page']);
this my function
function getProductsStore(Request $request)
{
$active_categories = [];
if(optional($request['query'] ??null)['active']!==null) {
$active_categories = $this->findChildren($request['query']['active']);
}
if (!empty($active_categories)) {
$categories = Category::whereIn('category_id', $active_categories)
->with('childrenRecursive')
->withCount('products', 'children')
->get();
} else {
$categories = Category::with('childrenRecursive')
->withCount('products', 'children')
->whereNull('category_id')
->get();
}
Log::info('in getprods');
Log::info(print_r($active_categories, true));
$pagination = $request->query('pagination');
$prod = Product::where('is_active', true)
->with(['categories', 'brand', 'images' => function ($query) {
$query->where('default', true);
}])
->Order($request)
->BrandStore($request)
->CategoryStore($request, $active_categories)
->paginate($request['pagination']['per_page'], ['*'], 'page', $pagination['page']);
return response()->json([
"products" => $prod->toArray()['data'],
"categories" => $categories,
"page" => $prod->currentPage(),
"pages" => $prod->lastPage(),
"per_page" => $request['pagination']['per_page'],
"total" => $prod->total(),
"sort" => "asc",
"field" => "product",
]);
}
@and94es so, use this
->paginate($pagination['per_page']), ['*'], 'page', $pagination['page']))
and it should works
Please or to participate in this conversation.