filter
方法使用给定的回调函数过滤集合的内容,只留下那些通过给定真实测试的内容:
$collection = collect([1, 2, 3, 4]); $filtered = $collection->filter(function ($value, $key) {
return $value > 2;
}); $filtered->all(); // [3, 4]
實例代碼:
//商家
$business= Business::Status(1)->get(); //帥選核銷關聯商家
$business_connect=$business->filter(function ($bus) {
return $bus->if_allow_connect == 1;
});
參考:https://segmentfault.com/q/1010000005021409