Lucia
Lucia

Reputation: 310

I need help in laravel 6 (search by name specialty and country in the same time)

I always get an error (Undefined nom) when I press the button of Search , I need someone who can solve this problem with me and correct my code: so this is my code :

Controller: doctors.php

 <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    use App\doctor;

    class doctors extends Controller
    {
        //
        function afficher()
        {
            $data=doctor::all(); 
            if ($data['nom']==$request->get("rech") && $data["spécialité"]==$request->get("spes") ) 
            {
                echo "voila la liste .$data.";   
            }else{ 
                echo "not found";
            }
        }

and this is the form: acceuil.blade.php

<form action="/doctors" method="GET">
    <div>
    <div class="form-row">
        <div class="col-4">
            <input type="text" class="form-control" placeholder="Tapez le nom de votre médecin" name="rech" value="">
        </div>
    <div class="col-2" z-index=1px>
        <select type="text" class="form-control" placeholder="Spécialité" name="spes">
            <option value="" disabled selected>Choisir la spécialité</option>
            <option value="1">Généraliste</option>
            <option value="2">Cardiologue</option>
            <option value="3">Pédiatre</option>
            <option value="3">Psychiatre</option>
            <option value="3">Gynécologue</option> 
        </select>
    </div>
    <div class="col-2">
        <select type="text" class="form-control" placeholder="" name="ville" > 
            <option value="" disabled selected>Région</option>
            <option ... >
        </select>
    </div>
    <div class="col-2">
        <input type="submit" value="RECHERCHER" class="btn btn-outline-primary">
    </div>
    </div>
</form>

Upvotes: 1

Views: 138

Answers (1)

Aman
Aman

Reputation: 62

Assuming you are having nom and spécialité column in your table doctors. If you want to fetch the data on behalf of the doctor model, then the query will be.

    $result = doctor::where('nom', $request->rech)
                  ->where('spécialité', $request->spes)
                  ->get(); 

Hope this will works for you.

Upvotes: 2

Related Questions