I am using this code in my controller and would like to know if this is good code to use or if I can write it better, or more compact, and so on. I am just trying to learn from this. It does work, so that is not my question.
public function search()
{
$search = Input::get('search');
$result = Categories::where('name', 'LIKE', '%'. $search .'%')->get();
if ($result->first()) {
$categories = Categories::where('name', 'LIKE', '%'. $search .'%')->Paginate(Auth::user()->categories);
Session::flash('alertMessage', 'The below results are filtered due to a search action!');
return View::make('categories.index', compact('categories'));
}
else {
$categories = Categories::orderBy('name', 'asc')->Paginate(Auth::user()->categories);
Session::flash('alertMessage', 'Your search has returned 0 results from the database.');
return View::make('categories.index', compact('categories'));
}
}