【发布时间】:2021-04-21 03:09:22
【问题描述】:
我想在模板布局中在我的网站上显示我的类别。我收到错误:“未定义变量:$product_cat”。
[家庭控制器]
public function index()
{
$bestseller = DB::select('select * from product where popular = ? AND p_status = ?', ['Yes', 'Active']);
$hotpick = DB::select('select * from product where p_hot = ? AND p_status = ?', ['Yes', 'Active']);
$product_cat = DB::table('pro_category')->where('pc_status', 'Active');
return view('welcome', ['bestseller'=>$bestseller], ['hotpick'=>$hotpick], ['product_cat'=>$product_cat]);
}
[welcome.blade.php]
@foreach($product_cat as $product_cat)
<div class="dropdown-menu full" aria-labelledby="dropdownMenuButton">
<center>
<a class="dropdown-item full" href="#">{{$product_cat->pc_name}}</a>
</center>
@endforeach
【问题讨论】: