1
I have a problem sending a parameter from one view to another. Until then beauty is working, but I’m having problems in paging, because it gives error in this parameter I need to send, to solve this need to leave this parameter nulo
, but for that would have to check if page was clicked.
You have to know that?
Follows the controller method:
public function index(Request $request)
{
$search = $request->get('search');
$btn = $request->query();
$products = DB::table('products')->when($search , function ($query) use ($search ) {
return $query->where('name', 'like', '%'. $search .'%' )
->orWhere('detalhe', 'like', '%'. $search .'%')
->orWhere('id', 'like', '%'.$search.'%');
})->paginate(5);
return view('products.index', compact('products','btn'))
->with('i', (request()->input('page', 1) -1)* 5);
//dd($btn);
// $products = Product::latest()->paginate(5);
//
// return view('products.index', compact('products','btn'))
// ->with('i', (request()->input('page', 1) -1)* 5);
}
one thing that could serve is to capture the current page, someone knows how to do this?
to get the current page, use
$pagina = $request->query('page');
- if you want to take the previous one, just subtract 1 or add 1 if you want the next page– Diego Vieira
That’s just what I wanted thanks Diego.
– teste