1public function search(Request $request){
2 // Get the search value from the request
3 $search = $request['search'];
4
5 // Search in the title and body columns from the posts table
6 $posts = Post::query()
7 ->where('title', 'LIKE', "%{$search}%")
8 ->orWhere('body', 'LIKE', "%{$search}%")
9 ->get();
10
11 // Return the search view with the resluts compacted
12 return view('search', compact('posts'));
13}