laravel if route is null or not existing redirect to other page
laravel if route is null or not existing redirect to other page i have a route is it possible that when the {id} does not exist it will redirect to a certain page or custom error page? something like if(id=null){return redirect etc..} Route::get('term/test/{id}', 'ListController@get_term_level'); public function get_term_level($id) { // $terms = Term::find($id); $terms=Term::with('level')->where('id','=',$id)->get(); if(is_null($terms)) { return redirect()->to('/mypage'); } else{ return view('term_level.index',compact('terms')); } } 3 Answers 3 You may try the following if you don't want to change your current data structure of view file. view public function get_term_level($id) { // $terms = Term::find($id); $terms = Term::with('level')->where('id','=...