This is my controller:
public function search(request $request)
{
$request->flash();
$search = $request->get('q');
$vehicles = vehicle::where('make', 'LIKE', '%'.$search. '%')
->orWhere ( 'model', 'LIKE', '%' . $search . '%' )
->orWhere ( 'year', 'LIKE', '%' . $search . '%' )
->paginate(9);
return view('user.vehicles.vehicles',compact('vehicles'));
}
Route:
Route::get('/vehicles/search', 'VehiclesController@search');
Laravel Blade
<form action="/vehicles/search" method="get">
<div class="row">
<div class="col-md-12 my-1">
<div class="input-group">
<input type="text" class="form-control" name="q" value="{{ old('q')}}" autocomplete="off" placeholder="Search for brand, model, year, etc">
<span class="input-group-btn">
<button class="btn btn-success" type="submit"><span class="fa fa-search"></span></button>
</span>
</div>
</div>
</div>
<form>
Problem:
When I search for ex: Toyota
, all Toyota in vehicle will show because of
where('make', 'LIKE', '%'.$search. '%')
But when I search for Toyota Innova 2013
, there is no result.
What I want: when I search for Toyota Innova 2013
, the code should show all the result from make
, model
and year