I have two search form one for the homepage and the other one is the other pages. The homepage search form searches the buildings while the other one searches the offices found in that page.
The homepage search form is working here is the code
BuildingController.php
$search = \Request::get('search');
$buildings = Building::where('name','like','%'.$search.'%')->orderBy('id', 'asc')->paginate();
return view('buildings')->with('buildings', $buildings);
buildings.blade.php
{!! Form::open(['method'=> 'GET','url'=>'/','role'=>'search']) !!}
<div class="input-group col-xs-4 col-md-6" >
<input type="text" name="search" class="form-control" placeholder="Search...">
<span class="input-group-btn">
<button type="submit" class="btn btn-info btn-md">Search</i>
</button>
</span>
</div>
{!! Form::close()!!}
And this is the other search form for offices which is not working whenever I click search it redirects me back to homepage
OfficeController.php
$searchoffice = \Request::get('searchoffice');
$offices = Office::where('name','like','%'.$searchoffice.'%')->get();
$data['building'] = $offices
return view('$offices',$data);
building.blade.php
{!! Form::open(['method'=> 'GET','url'=>'/','role'=>'$searchoffice']) !!}
<div class="input-group col-xs-4 col-md-6" >
<input type="text" name="searchoffice" class="form-control" placeholder="Search...">
<span class="input-group-btn">
<button type="submit" class="btn btn-info btn-md">Search</i>
</button>
</span>
</div>
{!! Form::close()!!}
Routes
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/', 'BuildingController@index')->name('index');
Route::get('building/{id}', 'PageController@show');
Route::get('buildings/create', 'BuildingController@create')->name('createbform')
Route::post('building/create/store', 'BuildingController@store')->name('createbuilding');
Route::get('building/{id}/edit', 'BuildingController@edit');
Route::post('building/{id}/edit', 'BuildingController@update')->name('editbuilding');
Route::get('building/{id}/delete', 'BuildingController@destroy');
Route::get('office/{id}', 'OfficeController@show')->name('officeMenu');
Route::get('building/{id}/offices/create', 'OfficeController@create')->name('createofficeform');
Route::post('building/{id}/offices/create/store', 'OfficeController@store')->name('createoffice');
Route::get('building/{id}/offices/edit', 'OfficeController@edit')->name('editofficeform');
Route::post('building/{id}/offices/edit', 'OfficeController@update')->name('editoffice');
Route::get('offices/{id}/delete', 'OfficeController@destroy')->name('deleteoffice');