My question is based on how I can pass the $searchResult in my Controller class so as I can use it to display the search result
This is my Controller
class SearchController extends Controller {
public function getHome($searchFor = null) {
$result = SearchPost::all();
return view('home', ['resulta' => $result]);
}
public function postSearch(Request $request) {
$this->validate($request, [
'searchString' => 'required|max:20|alpha',
]);
$searchFor = $request['searchString'];
//Connection with model(SearchPost) to search
$searchResult = SearchPost::search($searchFor);
return redirect()->route('home', ['searchFor' => $searchFor]);
}
}
Routes:
Route::get('/{searchFor?}', [
'uses' => 'SearchController@getHome',
'as' => 'home'
]);
Route::post('/search', [
'uses' => 'SearchController@postSearch',
'as' => 'search'
]);