我的 Laravel 刀片存在变量问题

问题描述

我的刀片有问题。运行项目时出现此错误

我的刀片代码

@foreach(\App\Category::all()->where('parent',$product->categories->where('parent','0')->first()->id )->first() as $category)
    <option data-id="{{ $category->id }}" value="{{ $category->id }}" {{ in_array($category->id,$product->categories->pluck('id')->toArray()) ? 'selected' : '' }}>{{ $category->name }}</option>
@endforeach
                           

显示错误

错误异常

试图获取非对象的属性“id”(视图:F:\Projects\Laravel Projects\NilfamShop\laravel\resources\views\admin\products\edit.blade.PHP

解决方法

这可能是错误:

$product->categories->where('parent','0')->first()->id )->first() 

也许你可以打电话:

 $product->categories->where('parent','0')->first()->id