Laravel 操纵返回的有说服力的集合
我的假设是,雄辩的回报收集,所以下面的工作Laravel 操纵返回的有说服力的集合,laravel,laravel-5,Laravel,Laravel 5,我的假设是,雄辩的回报收集,所以下面的工作 $all_locations = Service::getLocationsForService($service_id, 'all'); $chosen_locations = Service::getLocationsForService($service_id, $locations); $diff = $chosen_locations->diff($all_locations) 然而,我只得到了对undefined方法illumb
$all_locations = Service::getLocationsForService($service_id, 'all');
$chosen_locations = Service::getLocationsForService($service_id, $locations);
$diff = $chosen_locations->diff($all_locations)
然而,我只得到了对undefined方法illumb\Database\Query\Builder::diff()的调用。
这些是否仅在进行查询时可用,而不操纵已返回的集合
包括查询
public static function getLocationsForService($service_id, $locations)
{
if($locations[0] == 'all') { $locations[0] = ''; }
return Service::with(['types', 'contacts', 'locations.datetimes' =>function($q) use($service_id){
$q->where('service_id', $service_id);
}, 'conditions', 'locations' => function($query) use($locations) {
$ran = false;
foreach($locations as $location)
{
if(!$ran)
{
$query->Where('town', 'like', '%'.$location.'%')
->orWhere('city', 'like', '%'.$location.'%');
}
else
{
$query->orWhere('town', 'like', '%'.$location.'%')
->orWhere('city', 'like', '%'.$location.'%');
}
$ran = true;
$query->Where('published', 1);
}
}])->find($service_id);
}
您需要链接
get()
方法来执行查询并获取集合。试试这个:
$all_locations = Service::getLocationsForService($service_id, 'all')->get();
您需要链接
get()
方法来执行查询并获取集合。试试这个:
$all_locations = Service::getLocationsForService($service_id, 'all')->get();
问题是查询以find($id)结束;锁链拉着一切。我是否只需要将查找移动到where()?@CraigWard请显示所有相关代码
find()
将返回一个对象,而不是一个集合,但您的代码将返回一个查询生成器实例;锁链拉着一切。我是否只需要将查找移动到where()?@CraigWard请显示所有相关代码find()
将返回一个对象,而不是一个集合,但您的代码将返回一个查询生成器实例