
Hi Dev,
before, In laravel routes made in RouteServiceProvider.php file. but, Now laravel 12 give an option to configure about routes in app.php.
So, now you will have a question that if we want to create a custom route file without RouteServicesProvider.php file. so what will our next step.
But laravel 12 provides options in app.php file to define custom routes file options and you can customize routes from that file as well.
Before in laravel you created custom route file like below code:
app/Providers/RouteServiceProvider.php
public function boot() { $this->routes(function () { Route::middleware('web') ->prefix('admin') ->group(base_path('routes/admin.php')); }); }
Now, In laravel 12 you can create custom route file like below code.
bootstrap/app.php
<?php use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Exceptions; use Illuminate\Foundation\Configuration\Middleware; use Illuminate\Support\Facades\Route; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', channels: __DIR__.'/../routes/channels.php', health: '/up', then: function () { Route::middleware('web') ->prefix('admin') ->group(base_path('routes/admin.php')); } ) ->withMiddleware(function (Middleware $middleware) { // }) ->withExceptions(function (Exceptions $exceptions) { // })->create();
“It’s time to build your own admin.php file, adhering to the following structure.”
routes/admin.php
<?php use Illuminate\Support\Facades\Route; Route::get('/dashboard', [App\Http\Controllers\HomeController::class, 'index']); Route::get('/users', [App\Http\Controllers\UserController::class, 'index']); Route::get('/posts', [App\Http\Controllers\PostController::class, 'index']);
For seeing the list of routes you can run below command:
php artisan route:list
I hope it will assist you…