dom082186
2 years ago

Filtering data using fields and pagination

Posted 2 years ago by dom082186

I need to filter data using three input fields if i filter on the first two fields it's fine but when i put data on the third field it's been prioritized and the data in two field is not filtered.

Here is my controller

public function find_a_jobseeker ( Request $request ) {

$jobseekers_list = DB::table( 'users' )->where( [ [ 'role', 'jobseeker' ] ] )->whereNotNull( 'updated_at' )->latest()->paginate( 12 );

$queries = [];
$columns = [
    'position_applied', 'preferred_location', 'expected_salary'
];

foreach ( $columns as $column ) {
    if ( request()->has( $column ) ) {
        $jobseekers_list = DB::table( 'user_meta' )
            ->join( 'users', 'users.id', '=', 'user_meta.user_id' )
            ->where( [ [ 'meta_key', $column ], [ 'meta_value', 'like', request( $column ) . '%' ] ] )
            ->latest()
            ->paginate( 12 );
        $queries[ $column ] = request( $column );
    }
}

$jobseekers_list = $jobseekers_list->appends( $queries );

return view( 'pages.employers.find-a-jobseeker', [
    'page_name'     => 'find-a-jobseeker',
    'page_role'     => 'employers',
    'jobseekers'    => $jobseekers_list
]);

}

Please sign in or create an account to participate in this conversation.