phplaravel-11

When creating a Laravel project, is the kernel.php in the http and console folders already there? Why isn't it there in mine?


i have created a middleware

public function handle(Request $request, Closure $next)
    {
        if (!auth()->check() || auth()->user()->role !== 'admin') {
            abort(403, 'Unauthorized');
        }

        return $next($request);
    }

and also added to route

Route::middleware(['auth', 'admin'])->prefix('admin')->group(function () {
    Route::get('/dashboard', [AdminDashboardController::class, 'index'])->name('admin.dashboard');
});

and is it okay to add kernel.php manually? because kernel.php in app/http/ is not there, console folder is also not there

because i must add 'admin' => \App\Http\Middleware\AdminMiddleware::class,

So the point is why when I create a Laravel project there is no kernel.php


Solution

  • Laravel 11.x Kernel Structure Changes

    Since Laravel 11, the kernel.php files are no longer in the app/Http and app/Console folders as they were in previous versions. This is an intentional change to Laravel's architecture.

    What Happened to the Kernel Files?

    Laravel 11 completely redesigned its bootstrapping process. The traditional kernel classes (app/Http/Kernel.php and app/Console/Kernel.php) have been removed and their functionality is now handled directly in the framework core.

    How to Configure Middleware Now

    Instead of editing kernel files, you now configure middleware directly in the bootstrap/app.php file:

    use App\Http\Middleware\AdminMiddleware;
     
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->alias([
            'admin' => AdminMiddleware::class
        ]);
    })
    

    How to Register Console Commands

    Console commands are now registered using service providers or directly in the bootstrap/app.php file:

    ->withCommands([
        __DIR__.'/../app/Domain/Orders/Commands',
    ])
    

    Why This Changed

    This change is part of Laravel 11's effort to simplify the framework's architecture and reduce boilerplate code. By removing these files and integrating their functionality into the core framework, Laravel eliminated code that most developers didn't need to modify.

    If you're missing these files, it's because you're using Laravel 11.x, which has this new architecture.

    Check out the docs for more information https://laravel.com/docs/11.x/middleware