title: Simple search in laravel
body: <p>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..</p>
  
  <p>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.</p>
  
  <p>Here's my index method:</p>
  
  <pre><code>public function index(){
  
    $users = User::all();
    $service = Service::all();
  
    return view('browse.index', compact('users','service'));
  }
  </code></pre>
  
  <p>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: </p>
  
  <pre><code>  $category = $request-&gt;input('category');
  
    foreach ($users as $user) {
      $serviceFound = $user-&gt;service-&gt;where('category', 'LIKE', '%' . $category . '%');
    }
  </code></pre>
  
  <p>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...</p>