G
G
GaserV2017-04-22 19:02:04
Laravel
GaserV, 2017-04-22 19:02:04

How to implement multi-filter?

Tell. How to implement a job filter with pagination? Displaying all jobs with pagination was not difficult.
It will also not be difficult if, for example, the URL is of the form www.ru?city=ms.
But how to implement it if, for example, it will be www.ru?city=ms&type=1&var=0 ?
Right now it's just like this:

public function index(Request $request)
    {

      $jobs = Job::where('status', 1)->paginate(15);
      return view('index')->with('jobs', $jobs);

    }

PS I do not ask you to write the code for me. At least direct me to the right place)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
JhaoDa, 2017-04-22
@GaserV

https://laravel.com/docs/5.3/queries#conditional-c...

U
UksusoFF, 2017-04-23
@UksusoFF

https://github.com/Tucker-Eric/EloquentFilter

G
GaserV, 2017-04-23
@GaserV

Thank you all!) I am attaching the finished version.

public function index(Request $request)
    {
      $city = $request->city;
      $experience = $request->experience;
      $type = $request->type;
      $schedule = $request->schedule;

      $jobs = Job::when($city, function ($query) use ($city) {
                    return $query->where('city', $city);
                })
                ->when($type, function ($query) use ($type) {
                    return $query->where('type', $type);
                })
                ->paginate(15);

      return view('index')->with('jobs', $jobs);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question