【问题标题】:Trying to get property 'name' of non-object ? when i using pluck()试图获取非对象的属性“名称”?当我使用 pluck()
【发布时间】:2019-05-24 18:19:43
【问题描述】:
     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() 从数据库中检索数据时

【问题讨论】:

    标签: php laravel-5


    【解决方案1】:

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

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

    在刀片中执行此操作,

    @foreach($insurance as $pro)   
        <option value="{{ $pro }}">{{ $pro }}</option>
    @endforeach
    

    它应该可以工作。

    第一个参数是value,第二个是key

    【讨论】:

      猜你喜欢
      • 2021-09-03
      • 2019-05-23
      • 2019-07-11
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 2020-01-23
      • 2020-09-28
      相关资源
      最近更新 更多