在进行搜索的时候,维持搜索条件
我使用的是laravel8,在laravel中,在查询构造器中有一个appends方法,可以在查询的时候保持查询条件
如:
//搜索条件
$title = $request->query('title');//标题
$category_id = $request->query('category_id');//分类
//商品分页数据
$goods = Good::select('id', 'title', 'price', 'cover', 'category_id')
->where('is_on', 1)
->when($title, function ($query) use ($title) {
$query->where('title', 'like', "%{$title}%");
})
->when($category_id, function ($query) use ($category_id) {
$query->where('category_id', $category_id);
})
->withCount('comments')
->simplePaginate(20)
->appends([
'title' => $title,
'category_id' => $category_id
]);
在有查询条件的时候
无查询条件的时候
我使用的是阿里云的短信包。 如果是让我们直接写短信扩展发送的话,工作量是非常大的,所以,我使用的是外部扩展包 去packagist中搜索sms 我使用的是这一个 安装命令 composer require overtrue/easy-sms 这是一款满足你的多…
版权声明:
作者:linrux
链接:https://www.tot7.cn/technology/php/65.html
来源:阿信博客
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
共有 0 条评论