试图根据多个值的任意组合过滤集合对象。这是我所知道的。没有发生。任何线索对我来说?过滤Eloquent集合
public function search()
{
$posts = Posting::all();
$type_id = Input::get('type_id');
$country_id = Input::get('country_id');
$province_id = Input::get('province_id');
$posts = $posts->filter(function($post)
{
if(!empty($type_id) && $type_id>0)
{
return $post->where('type_id','=',$type_id);
}
})->values();
$posts = $posts->filter(function($post)
{
if(!empty($country_id) && $country_id>0)
{
return $post->where('country_id','=',$country_id);
}
})->values();
$posts = $posts->filter(function($post)
{
if(!empty($province_id) && $province_id>0)
{
return $post->where('province_id','=',$province_id);
}
})->values();
return $posts;
}
赞赏任何帮助。
你能显示什么Input :: all()返回? – Jazerix
宣布$ post在哪里?你确定你在返回结果时不是指$ post? – Jazerix
$ post是关闭参数的名称:'$ posts = $ posts-> filter(function($ post)'。 – RSAdmin