title: Laravel 5.3 Search function in API
body: <p>I'm implementing an API for <code>front end and mobile apps</code> now i'm working on <code>search function</code> where a user may type <code>column name</code> or any <code>data</code> i should be able to provide the data they request in a JSON format </p>
  
  <p>i really don't know how to query based on the data they input, so for i did this</p>
  
  <p>in my controller</p>
  
  <pre><code>public function getSearchResults(Request $request) {
      $search_drivers = Driver::all();
  
      return Response::json([
          'data' =&gt; $search_drivers-&gt;all()  // i know this is not cool, i need to query based on the input data
      ]);
  }
  </code></pre>
  
  <p>my model is</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Database\Eloquent\SoftDeletes;
  
  class Driver extends Model
  {
     use SoftDeletes;
  
     protected $fillable = [
                             'agent_id',
                             'registration_center',
                             'registration_date',
                             'sponsor_name',
                             'event_name',
                             'registration_id',
                             'profile_photo',
                             'first_name',
                             'last_name',
                             'role',
                             'date_of_birth',
                             'marital_status',
                             'phone_number',
                             'alternate_phone_number',
                            ];
  
     protected $dates = ['deleted_at'];
  }
  </code></pre>
  
  <p>and in my routes </p>
  
  <pre><code>Route::group(['prefix' =&gt; 'v1', 'middleware' =&gt; 'auth:api'], function() {
      Route::get('user', function (Request $request) {
          return $request-&gt;user();
      }); 
      Route::resource('drivers', 'DriversController');
      Route::resource('search', 'DriversController@getSearchResults'); //search route
  });
  </code></pre>
  
  <p>and the parameters meight be</p>
  
  <pre><code>   http://localhost:8000/api/v1/search?data=name(maybe any column data from above model)
  </code></pre>
  
  <p>could you please tell me or give me some example how to <code>query and return as json</code></p>
  
  <p>Thank You</p>