laravel when的用法

laravel when的用法

```
public function taskItemList(Request $request)
{
$templateId = $request->input('template_id', null);
$taskId = $request->input('task_id', null);
$taskItem = PushTaskItem::query()
->when($templateId !== null, function ($query) use ($templateId) {
$query->where('template_id', $templateId);
})
->when($taskId !== null, function ($query) use ($taskId) {
$query->where('task_id', $taskId);
});

$count = $taskItem->count();
}
```

    A+
发布日期:2023年04月29日  所属分类:未分类

发表评论

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