lundi 23 mai 2016

Laravel where statement and pagination

I have an SQL search where I use Eloquent whereRaw, and than paginatate results.

Proplem: the results are paginated and if I navigate to the next page the results will be gone and it will just "SELECT All " bacause laravel's pagination sends only ?page= GET request.

code:

if (Input::has('city')) {
        $query .= ' and city = '.Input::get('city');
    }
    if (Input::has('area')) {
        $query .= ' and area = '.Input::get('area');
    }
    if (Input::has('sub_location')) {
        $query .= ' and sub_location = '.Input::get('sub_location');
    }
    if (Input::has('rent')) {
        $query .= ' and rent = '.Input::get('rent');
    }
    if (Input::has('price_min') && Input::has('price_max')) {
        $query .= ' and price < '.Input::get('price_max').' and price >'.Input::get('price_min');
    }


    $listings = ListingDB::whereRaw($query)->paginate(5);


    return View::make('page.index')->with('title','Home')->with('listings',$listings);

so when I navigate to the next page all the Input is gone because laravel generates pagination only with ?page= GET variable, how can I solve it?

thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire