Answers for "laravel post request search query"

PHP
0

laravel post request search query

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'));
}
Posted by: Guest on September-18-2021

Browse Popular Code Answers by Language