首页 > 解决方案 > 此集合实例上不存在属性 [x] 使用 with() 和多态

问题描述

Property [status] does not exist on this collection instance当我尝试获取列的值时出现此错误,这是我的代码

$lab = Lab::select('id', 'services_cat_id', 'resp_doctor_id', 'invoice_id', 'xray_file', 'status', 'note')->where('patient_id', '3')
        ->with(['invoice' => function ($q) {
            $q->select('invoiceable_id','id', 'code', 'status');}])
        ->orderBy('status', 'ASC')
        ->get();

在刀片中:

@foreach ($lab as $item)

{{$item->invoice->status}}

标签: phpmysqllaraveleloquent

解决方案


推荐阅读