webfuelcode
1 month ago

Eloquent where() for two column match

Posted 1 month ago by webfuelcode

Trying to create a search result for posts that will search on the title and description column.

I can make it happen like this for one:

public function search(Request $request)
    {
        $this->validate($request, [
            'q' => 'required',
        ]);
        $links = Link::where('title', 'like', '%' . $request->q . '%')->get();
    
        return view('links.search', compact('links'));
    }

How to set it for two different columns in one search...like $links = Link::where('title', 'like', '%' . $request->q . '%')->get(); and $links = Link::where('description', 'like', '%' . $request->q . '%')->get();

Please sign in or create an account to participate in this conversation.