php - Laravel - Check for another URL prefix if exists -
how can skip wildcard route check route before returning 404?
route::get( '{user}', function( $user ){ // checking existing user if( $user = user::getuser( $user ) ) return view( 'templates.user', [ 'user' => $user ] ); // should check prefixes before return 404 return abort( 404 ); }); route::get( 'foopage', function(){ return view( 'templates.foo' ); });
from code above, if access /foopage
returns 404 because of no username 'foopage' exist.
but it's supposed show view( 'templates.foo' )
move statement route::get( 'foopage', function(){ return view( 'templates.foo' ); });
above user route statement.
route::get( '{user}', function( $user ){ ... });
this because laravel prioritise order of routes defined , if foopage route defined below user routes, consider foobar user route , try go down path.
wiki
Comments
Post a Comment