laravel 5.1 - Pagination doesn't work after perform search -
i have form in laravel. used pagination
in form , search option too. pagination works fine when didn't search anything. if search has records more 10 (my pagination record limit 10), shows result in first page in second page or third page shows records of whole database. it's ignore search criteria.
controller code:
public function index() { if (input::has('invoicenumber')) { $invoicenumber = input::get('invoicenumber'); $invoices = invoice::where('invoicenumber','like', '%'.$invoicenumber.'%')->orderby('date','desc')->paginate(10); } elseif (input::has('client')) { $client = input::get('client'); $invoices = invoice::where('client','like', '%'.$client.'%')->orderby('date', 'desc')->paginate(10); } elseif (input::has('startdate') && input::has('enddate')) { $startdate = input::get('startdate'); $enddate = input::get('enddate'); $invoices = invoice::wherebetween('date', [$startdate, $enddate])->orderby('date', 'desc')->paginate(10); } elseif (input::has('startdate')) { $startdate = input::get('startdate'); $invoices = invoice::where('date', $startdate)->orderby('date', 'desc')->paginate(10); } elseif (input::has('enddate')) { $enddate = input::get('enddate'); $invoices = invoice::where('date', $enddate)->orderby('date', 'desc')->paginate(10); } else { $invoices = db::table('invoices') ->join('vehicles', 'invoices.vehicle', '=', 'vehicles.registration') ->select( 'invoices.*', 'vehicles.brand', 'vehicles.model', 'vehicles.seat', 'vehicles.remarks' ) ->orderby('date', 'desc') ->paginate(10); } return view('invoice.index',compact('invoices')); }
after performing search url this:
http://my-site.com/invoice?invoicenumber=&client=&startdate=2016-01-01&enddate=2016-02-08
after search when click on page 2, url become this:
http://my-site.com/invoice?page=2
in view file, render has given below:
{!! $invoices->appends(input::except('page'))->render() !!}
Comments
Post a Comment