I am creating a simple search form of my posts. It is returning the posts but ignoring the search term and it just displays all the posts. I see the correct term in the URL. Here is the function in the PostController
public function search(Request $request) {
// Get the search value from the request
$search = $request->input('search');
// Search in the title and body columns from the posts table
$posts = Post::query()
->where('title', 'LIKE', "%{$search}%")
->orWhere('body', 'LIKE', "%{$search}%")
->take(3)
->get();
// Return the search view with the resluts compacted
return view('search-results', compact('posts'));
}
Here is the search results
if($posts->isNotEmpty())
@foreach ($posts as $post)
{{ $post->title }}
image }}">
@endforeach
@else
No posts found
@endif
This is the form