laravel框架中对集合进行过滤

平时对二维数组进行处理

都是foreach觉得太土了

其实可以通过laravel的集合filter操作来实现

```
public function index(Phone $request){
try{
$list = UserCouponService::getByMobile($request);
if($request['is_use'] == 0){
$list = $list->filter(function ($item,$key){
$use_start_date = $item['use_start_date'];
$use_end_date = $item['use_end_date'];
$is_expire = UserService::checkCouponExpire([
'use_start_date' => $use_start_date,
'use_end_date' => $use_end_date,
]);
return $is_expire == 0;
});
}
return $this->jsonData(User::collection($list));
}catch (\Exception $e){
return $this->jsonError($e->getMessage());
}
}
```

    A+
发布日期:2022年10月18日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: