平时我们做搜索功能可能需要对文章标题,文章内容进行查找搜索,Laravel中多字段查询主要用到whereRaw,该方法可以实现多字段进行查找数据。
<?php
namespace App\Http\Controllers\Index;
use App\Http\Controllers\Controller;
use App\Models\Index\Note;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class SearchController extends BaseController
{
public function search(Request $request){
if ($request->filled('searchkey')) {
$notelist=DB::table('note')
->whereRaw("concat(title,content) like ?",["%$request->searchkey%"])
->paginate(17);
}
}
}
?>上面方法实现对文章的标题和内容进行搜搜查找,共大家参考。
关于简忆
简忆诞生的故事



粤ICP备16092285号
文章评论(0)