我在这里遇到问题,我不太确定是什么问题。我在查询中获取了序列化的商业类别(类别),然后为每个我尝试反序列化,但结果我只得到第一个项目的反序列化类别。
这是我的代码:
$businesses= Businesses::where('visible' , 'yes')->where( 'delete' , 'no')->select('categories')->get();
foreach ($businesses as $key => $business) {
$categories = unserialize($business->categories);
return view('test',['categories'=>$categories]);
}
答案 0 :(得分:0)
请检查这是否对您有帮助,
$businesses= Businesses::where('visible' , 'yes')->where( 'delete' , 'no')->select('categories')->get();
$categories = array();
foreach($businesses as $key => $business) {
$categories[] = unserialize($business->categories);
}
return view('test',['categories'=>$categories]);
问题:您将在foreach循环的第一次迭代中返回类别 建议:你可以在foreach循环中创建一个关联数组&循环后返回视图。然后在视图中,您可以使用类别