我正在使用带有Vuejs的Laravel。我显示了以下查询,它显示了产品,但是在查询分页时,它给了我以下错误:"试图访问null"类型值上的数组偏移量,异常:"ErrorException">
我查询:
$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']);
错误给了我:->paginate($request['pagination']['per_page'], ['*'], 'page', $pagination['page'])
;
$pagination = $request->pagination;
dd($pagination);
如果有正确的值-使用它。否则指定默认值
->paginate(Arr::get($pagination, 'per_page', 60), ['*'], 'page', Arr::get($pagination, 'page', 1))