📅  最后修改于: 2022-03-11 14:54:05.555000             🧑  作者: Mango
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'));
}