Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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'));
}
 
PREVIOUS NEXT
Tagged: #laravel #post #request #search #query
ADD COMMENT
Topic
Name
8+1 =