📜  laravel 发布请求搜索查询 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:05.555000             🧑  作者: Mango

代码示例1
public function search(Request $request){
    // Get the search value from the request
    $search = $request['search'];

    // Search in the title and body columns from the posts table
    $posts = Post::query()
        ->where('title', 'LIKE', "%{$search}%")
        ->orWhere('body', 'LIKE', "%{$search}%")
        ->get();

    // Return the search view with the resluts compacted
    return view('search', compact('posts'));
}