在Laravel的搜索控制器中,我试图将字符串'$ travelIdea-> tags'拆分为数组'$ listtags',然后执行对每个$ listtags [$ i]的搜索,但失败了(在if($ scope =='Destination')的“ Else”部分中)。
我知道我应该做的事情类似于for循环。
有人可以给我一些建议吗?
public function search(Request $request)
{
$search = $request->get('search');
$partialsearch = $request->get('partialsearch');
$scope = $request->get('scope');
if($scope == 'Destination'){
if($partialsearch)
$travelIdea=TravelIdea::where('destination','LIKE','%'.$search."%")->get();
else $travelIdea=TravelIdea::where('destination','%'.$search."%")->get();
}
else {
$listtags = explode(',', $travelIdea->tags);
$foreach($i as $i){
if($partialsearch)
$travelIdea=TravelIdea::where('listtags[$i]','LIKE','%'.$search."%")->get();
else $travelIdea=TravelIdea::where('listtags[$i]','%'.$search."%")->get();
return view('travelIdea.search', compact('travelIdea'));
});
}
}