Hey all, I currently have a single-page Laravel application, super simple. It displays data from a database and allows for the data to be sorted and searched through.
I currently handle all my searching and sorting in the routing file, but it's getting lengthy and I was wondering if it would be best practice to move it to its own controller. Is there a standard for when a controller should be used vs when it would be a waste?
My "searching" route currently looks like:
Route::get('/search', function () {
$orderParam = Input::get('order');
$searchTitle = Input::get('searchtitle');
$archived = Input::get('archive_flag');
//Might no longer need series of if checks, but good to work with manual URL parameters I guess
$query = DB::table('proposals');
if(Input::has('archive_flag')){
$query->where('archive_flag', '=', $archived);
}
if(Input::has('searchtitle')){
$query->where('title', 'LIKE', '% ' . $searchTitle . '%');
}
if(Input::has('order')){
$query->orderBy($orderParam);
}
$proposals = $query->get();
$numResults = $query->count();
$documents = DB::table('prop_documents')->get();
$comments = DB::table('prop_status')->get();
return view('index', ['proposals' => $proposals, 'documents' => $documents, 'comments' => $comments, 'numResults'=>$numResults]);
});
Thanks to anyone who can provide some insight