Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hasan_Yagout's avatar

laravel 11 custom route

my routes have prefixes and i can't seem to configure it correctly in my system Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.'], function () {

Route::get('/', function () {
    return redirect()->route('admin.auth.login');
});

}); this is an example from my admin routes

0 likes
4 replies
gych's avatar

Try this instead, its the new way of defining route groups with prefix() and name()

Route::namespace('Admin')->prefix('admin')->name('admin.')->group(function () {
	Route::get('/', function () {
    	return redirect()->route('admin.auth.login');
	});
}); 

https://laravel.com/docs/11.x/routing#route-group-prefixes

EDIT: I had a typo in the code, I've corrected it.

Hasan_Yagout's avatar

@gych your answer is nice i will try it but what i ment is that the new way of registering routes is in bootstrap/app.php and i couldn't register my routes i have routes for web and routes for admin this is my bootstrap/app.php Application::configure(basePath: dirname(DIR)) ->withRouting( web: DIR.'/../routes/web.php', commands: DIR.'/../routes/console.php', health: '/up',

)
->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'maintenance_mode' => MaintenanceModeMiddleware::class,
        'isMobile' => EnsureIsMobileMiddleware::class,

    ]);
})
->withExceptions(function (Exceptions $exceptions) {
    //
})->create();

how to register web routes and admin routes and this is just an example of my admin routes in a separate file. ignore the closing brackets Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.'], function () {

Route::get('/', function () {
    return redirect()->route('admin.auth.login');
});

/*authentication*/
Route::group(['namespace' => 'Auth', 'prefix' => 'auth', 'as' => 'auth.'], function () {
    Route::get('/code/captcha/{tmp}', 'LoginController@captcha')->name('default-captcha');
    Route::get('login', 'LoginController@login')->name('login');
    Route::post('login', 'LoginController@submit')->middleware('actch');
    Route::get('logout', 'LoginController@logout')->name('logout');
});
gych's avatar

@Hasan_Yagout

In your routes folder create a new file admin.php which you can use to add all the admin routes

Then in boostrap/app.php add the route group to the already existing withRouting() like this

    ->withRouting(
        web: __DIR__ . '/../routes/web.php',
        commands: __DIR__ . '/../routes/console.php',
        health: '/up',
        then: function () {
            Route::namespace('Admin')->prefix('admin')->name('admin.')->group(base_path('routes/admin.php'));
        },
    )

If you use roles to protect your admin routes you should also add middleware to this Route group.

View this link to read more info about this in the Laravel docs https://laravel.com/docs/11.x/routing#routing-customization

1 like
Snapey's avatar

If you are having problems make sure you list the routes and check what Laravel's understanding is of what you want.

Oh, and make sure you run php artisan route:clear

Please or to participate in this conversation.