1 2 3 4 5 6 7 8 9 10 11 12 |
$offset = $request->has('offset') ? $request->query('offset') : 0; $limit = $request->has('limit') ? $request->query('limit') : 10; $sorgu = product::query(); if($request->has('q')) $sorgu->where('product_name','like','%'.$request->query('q').'%'); if($request->has('sortby')) $sorgu->orderBy($request->query('sortby'),$request->query('sort','desc')); $data = $sorgu->offset($offset)->limit($limit)->get(); return response($data,200); |
product?q=elma&sortby=id&sort=desc&limit=2
linkini yukarıdaki kod ile çalıştırabiliriz.