Search for registration from a form in Laravel [closed]

0

I need to place a search field in a form and if it finds the record in the database, complete the form data retrieved from the database, I can perform the search in the index method, which shows me the data in a table, but I want to do the same but for a form, I'm working on laravel 5.5.

For example, if you enter the doctor's routine and it already exists, you should recover the data from the database, otherwise indicate that it is not registered.

Thanks in advance to anyone who can help me

    
asked by K E 27.12.2017 в 22:18
source

1 answer

1

You must create an api in laravel and recover the data through ajax.

To create the api:

You must create the path in the file api.php , for example:

Route

 Route::get("doctor/{rut}", "DoctorController@getInfoDoctor");

//Metodo en controlador

//Usando eloquent

public function getInfoDoctor($rut){

    $doctor = App\Doctor::whereRut($rut)->first();


    if(isset($doctor)){

       return response()->json("doctor" => $doctor);

    }else{

        return "No se enceontraron resultados" ;

   }

}

After making the previous backend you must make the ajax call with javascript when the user presses the search button of rut.

So with the $ doctor object, you can get all your information.

    
answered by 09.05.2018 в 19:16