所以,我的代码中有一些错误,当我输入姓名、专业和城市时,我希望搜索框能工作,但它不再工作了,所以这是我的控制器代码:
public function chercher (Request $request) {
$doctors=medecin::orderBy('created_at','desc')->get();
$rech=$request->get('rech');
$spec=$request->get('spec');
$ville=$request->get('Région');
$S=medecin::orderBy('created_at','desc')->get()
->where('Spécialité',$spec) ;
$SV=medecin::orderBy('created_at','desc')->get()
->where('Spécialité',$spec)
->where('Ville',$ville);
$SN=medecin::orderBy('created_at','desc')->get()
->where('Spécialité',$spec)
->where('Nom',$rech) ;
$SNV=medecin::orderBy('created_at','desc')->get()
->where('Spécialité',$spec)
->where('Nom',$rech)
->where('Ville',$ville);
$V=medecin::orderBy('created_at','desc')->get()
->where('Ville',$ville);
$N=medecin::orderBy('created_at','desc')->get()
->where('Nom',$rech);
$NV=medecin::orderBy('created_at','desc')->get()
->where('Nom',$rech)
->where('Ville',$ville) ;
return view ('doctors' ,['doc'=> $doctors,$S,$SV,$SN,$SNV,$V,$N,$NV],['tab'=>[$rech,$spec,$ville]]); }
这是视图:
{{$tab[0]}}
{{$tab[1]}}
{{$tab[2]}}
<ul>
@if($tab[1]=='Dentiste' && $tab[2]=='Tunis' && $tab[0]=='' )
@foreach($doc[0] as $show)
<h1> Dr.{{$show->Nom}} {{$show->Prénom}} </h1> </br>
<h1> {{$show->Photo}} </h1>
<h1>{{$show->Spécialité}} </h1>
<h1>{{$show->Ville}}</h1>
@endforeach
@elseif($tab[1]=='' && $tab[2]=='' )
@foreach($doc[2] as $show)
<h1> Dr.{{$show->Nom}} {{$show->Prénom}} </h1> </br>
<h1> {{$show->Photo}} </h1>
<h1>{{$show->Spécialité}} </h1>
<h1>{{$show->Ville}}</h1>
@endforeach
@elseif ($tab[0]=='' && $tab[2]='')
@foreach ($doc[7] as $show)
<h1> {{$show->Nom}} {{$show->Prénom}} </h1> </br>
<h1> {{$show->Photo}} </h1>
<h1>{{$show->Spécialité}} </h1>
<h1>{{$show->Ville}}</h1>
@endforeach
如果我单击搜索按钮,则会出现此错误:
试图获取非对象的属性“Nom”(查看:C:\xampp\htdocs\Doctor\resources\views\doctors.blade.php)
aluckdog