This is how you can use the search function used in the Laravel project.

Search the post and show all the results that match its title or description.

public function search(Request $request)
    {
        $this->validate($request, [
            'q' => 'required',
        ]);
        $posts = Post::where('title', 'like', '%' . $request->q . '%')->orWhere('description', 'like', '%' . $request->q . '%')->paginate(20);
    
        return view('pages.search', compact('posts'))->with('i', (request()->input('page', 1) - 1) * 20);
    }

Related Posts