I'm trying to build a search system in my small laravel project but considering that I'm still a beginner I can't figure how this should work..
Basically, I have a controller which returns an index page with all the users. In the index page I have multiple select tags where you can choose an option and filter the users.
Here's my index method:
public function index(){
$users = User::all();
$service = Service::all();
return view('browse.index', compact('users','service'));
}
Now, the thing is, I have a relationship built between users and services. So, each user hasMany services. With that in mind, when I'm building the search function I want to be able to access the user service. Something like this:
$category = $request->input('category');
foreach ($users as $user) {
$serviceFound = $user->service->where('category', 'LIKE', '%' . $category . '%');
}
Of course this doesn't work because considering that I have a get route for my index, I don't know how to set up the form so I can use the $request.. I hope this is clear...Maybe you guys can help me with setting up the form/route and clear my mind on how should I do this...