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

试图获取非对象的属性“名称”?当我使用 pluck()

试图获取非对象的属性“名称”?当我使用 pluck()

PHP
红糖糍粑 2021-06-29 13:53:09
  Trying to get property 'name' of non-object? when i using pluck() for retrive data from database//a.contoller            public function index(){      $insurance = Insurance_Providers::pluck('id','name');      $physicians = Physicians::pluck('id','pp','sp');      $pharmacies = Pharmacies::pluck('id','name');      return view('auth.profile',compact('insurance','physicians','pharmacies'));    }//a.blade.php    <select name="insurance" id="ip" class="form-control" required>    <option value="">Insurance Provider</option>     @foreach($insurance as $pro)   <option value="{{ $pro->name }}">{{ $pro->name }}</option>     @endforeach     </select>试图获取非对象的属性“名称”?当我使用 pluck() 从数据库中检索数据时
查看完整描述

1 回答

?
蝴蝶刀刀

TA贡献1801条经验 获得超8个赞

您在 pluck 中使用了三个参数,


$insurance = Insurance_Providers::pluck('name', 'id'); // name is value and id is key

在刀片中这样做,


@foreach($insurance as $pro)   

    <option value="{{ $pro }}">{{ $pro }}</option>

@endforeach

它应该工作。


第一个参数是值,第二个是键


查看完整回答
反对 回复 2021-07-09
  • 1 回答
  • 0 关注
  • 170 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信