Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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));
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

public function index(Request $request)
{
    $results = Property::whereBetween('price', [1000, 10000]);
    $conditions = [];

    if ($request->has('select_menu')) {
        $conditions['city'] = $request->city;
        $conditions['area'] = $request->area;
        $conditions['purpose'] = $request->status;
        session(['formDataSession' => $conditions]);
    }
    $getSession = session('formDataSession');
    $conditions['city'] = $getSession['city'];
    $conditions['area'] = $getSession['area'];
    $conditions['purpose'] = $getSession['purpose'];
    $results = $results->where($conditions)->paginate(6);

    return view('search', ['page' => 'search', 'results' => $results]);
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!