【发布时间】:2018-06-14 02:13:20
【问题描述】:
我发现了很多类似的问题,但对我来说没有真正的解决方案。
我有一个关于 Laravel 5.4 的项目
现在,在我的控制器中,我正在为我的搜索准备过滤器。
所以,想象一下我想按我的Cv 模型的“位置”和“关于”字段过滤我的搜索。
所以,我发现每个这样做的人都有不同的价值
$arrOfTags = explode(',', $request['position']);
//separate basic search request(using some js modules that return a request with "," separator.
//Basically, find a Cv where location of "positions" is distinct
$filter0 = Cv::select('location')
->whereIn('position', $arrOfTags)
->groupBy('location')
->get();
$filter1 = Cv::select('about')
->whereIn('position', $arrOfTags)
->groupBy('about')
->get();
现在,我想将这 2 个结果连接到名为 $filters 的对象中
然后,在我的 Blade 中使用它:
@foreach($filters as $filter)
<li> <input type="checkbox" name="location" value="{{$filter->location}}"/> <span> {{$filter->location}} </span> </li>
@endforeach
@foreach($filters as $filter)
<li> <input type="checkbox" name="location" value="{{$filter->about}}"/> <span> {{$filter->about}} </span> </li>
@endforeach
我尝试了对象的array_merge,创建了一个新的空对象并设置了这个对象和其他东西的参数,但没有成功。
【问题讨论】:
-
@VinayMulgund 它返回给我 htmlspecialchars() 期望参数 1 是字符串,给定对象(查看:/home/primo/jobiMarket/resources/views/filtersForSearch.blade.php)这意味着 resultObject 是空的。