为了账号安全,请及时绑定邮箱和手机立即绑定

试图获取非对象的属性“Nom”

试图获取非对象的属性“Nom”

PHP
慕码人2483693 2022-10-09 19:55:48
所以,我的代码中有一些错误,当我输入姓名、专业和城市时,我希望搜索框能工作,但它不再工作了,所以这是我的控制器代码: 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)
查看完整描述

1 回答

?
aluckdog

TA贡献1847条经验 获得超7个赞

在你看来,

@foreach($doc[0] as $show)

应该

@foreach($doc as $show)

因为你应该迭代医生的数组。

通过做

@foreach($doc[0] as $show)

相反,您正在迭代一个医生对象的属性,这不是您想要的。


查看完整回答
反对 回复 2022-10-09
  • 1 回答
  • 0 关注
  • 117 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号