K
K
Konstantin Malyarov2017-08-08 22:47:27
Laravel
Konstantin Malyarov, 2017-08-08 22:47:27

How to find by model if the model is not complete?

On the main page there is a Request that receives data from the form

public function index(Request $request)
    {
        if ($request->surname != null || $request->first_name != null || $request->second_name != null || $request->birthday != null) {
            $patient = new Patient();
            $patient->surname = $request->surname;
            $patient->first_name = $request->first_name;
            $patient->second_name = $request->second_name;
            $patient->birthday = $request->birthday;
            $patients = Patient::orWhere('surname', $patient->surname)
                ->orWhere('first_name', $patient->first_name)
                ->orWhere('second_name', $patient->second_name)
                ->orWhere('birthday', $patient->birthday)
                ->get();
            return view('staff_doctor.patient.index', compact('patients', 'patient'));
        } else {
            $patients = Patient::all()->sortBy('surname')->sortBy('first_name')->sortBy('second_name')->sortBy('birthday');
            return view('staff_doctor.patient.index', compact('patients'));
        }
    }

If the entire form is filled out, then it finds the patient in the database, if part of it does not find anyone.
How to make it so that only the last name and birthday fields are filled in and search for all matches in the database.
For example, if I search for 01/01/1911, then it will return:
Ivanov Ivan Ivanovich 01/01/1991
Petrov Petr Petrovich 01/01/1991
And if Ivanov:
Ivanov Ivan Ivanovich 01/01/1991
Ivanov Ivan Ivanovich 02/01/1991

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question