讨论数量:
public static function searchCon(array $validated)
{
return function ($query) use ($validated) {
extract($validated);
// 关键字搜索
if (filled($keyword)) {
$query->where('name', 'like', '%' . $keyword . '%');
}
// 状态筛选
if (filled($status)) {
$query->where('status', $status);
}
if (filled($type)) {
$query->where('type', $type);
}
if (filled($pid)) {
$query->where('pid', $pid);
}
};
}
@PhoenixIcy 他提供的这种写法很赞
推荐文章: