我试图根据表中的特定列是1还是0显示标题。在我的控制器中,我已经(编辑了一些不相关的代码:]]
public function show(Company $id){ $vegan = Company::find($id); $vegetarian = Company::find($id); return view('allProducts')->with([ 'vegan' => $vegan, 'vegetarian' => $vegetarian, ]); }
并且在我看来:
@if($vegan->vegan == 1) <h3 class="text-center">Vegan</h3> @endif
但是我收到错误消息
ErrorException (E_ERROR) Property [vegan] does not exist on this collection instance. (View: C:\xampp\htdocs\EdenBeauty\resources\views\allProducts.blade.php)
我尝试过以下操作,但每次都会出错:
@if($vegan[0]->vegan == 1)
这会产生未定义的偏移量错误
我正在尝试根据表中的特定列是1还是0显示标题。在我的Controller中,我(编辑了一些不相关的代码):public function show(Company $ id){$ vegan =。 ..
问题是您在查询后缺少first()
:
在此行中,您正在通过URL参数将Company
注入到show
方法中: