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

575

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 >
    <div >
      <input type="text" placeholder="Tapez le nom de votre médecin" name="rech" value="">
    </div>
  <div z-index=1px>
    <select type="text" 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 >
    <select type="text" placeholder="" name="ville" > 
      <option value="" disabled selected>Région</option>
      <option ... >
    </select>
  </div>
  <div >
    <input type="submit" value="RECHERCHER" >
  </div>
  </div>
</form>
671

Answer

Solution:

Assuming you are havingnom andspécialité column in your tabledoctors. If you want to fetch the data on behalf of thedoctor model, then the query will be.

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

Hope this will works for you.

People are also looking for solutions to the problem: php - Restrict duplication in single input field

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.