vendredi 28 avril 2017

Laravel Paginator with post form data search with session stores

i have searching routes with get and post. First time users select search filters from home page then it submit it hit on index controller search with form data and return correct results with pagination when i click on pages it does not show any thing.

Route::post('search', 'SearchController@index');
Route::get('search', 'SearchController@index');

And i have index controller for search with post first time and with session like this.

public function index(Request $request)
    {
       if( Request::get('select_menu') !='' ){
            $conditions = array();
            $conditions['city'] = Request::get('city');
            $conditions['area'] = Request::get('area');
            $conditions['purpose'] = Request::get('status');
            $results = Property::where($conditions)->whereBetween('price', array(1000, 10000))->paginate(6);
            Session::set('formDataSession', $conditions);
        }
    elseif(Session::has('formDataSession')){
            $getSession = Session::get('formDataSession');
            $conditions = array();
            $conditions['city'] = $getSession['city'];
            $conditions['area'] = $getSession['area'];
            $conditions['purpose'] = $getSession['purpose'];
            $results = Property::where($conditions)->whereBetween('price', array(1000, 10000))->paginate(6);

        }
return view('search', array('page' => 'search','results'=>$results));

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire