Laravel 11 - Kernel.php 제거
Laravel 11에서는 Kernel, cast, Console kernel이 제거되었다고 한다.
Laravel 9 버전의 공식 문서를 통해 sanctum을 설치하려고 하면,
SPA를 사용할 계획이 있는 경우 app/Http/Kernel.php에서 api 미들웨어 그룹을 찾아 배열 요소를 추가하라고 한다.
Laravel 11의 Kernel.php에 해당하는 내용은 app/bootstrap/app.php 파일로 이동되었다.
sanctum 기준으로 해당 파일의 withMiddleware 메서드 안쪽에 아래와 같이 추가하면 된다.
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->appendToGroup('api', [
EnsureFrontendRequestsAreStateful::class,
'throttle:api',
SubstituteBindings::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
모델의 casts 항목은 사용해본적이 없으니 넘어가고, 콘솔 커맨드의 경우는 routes/console.php에 모두 입력하면 된다고 한다.
<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Shcedule;
Artisan::command('inspire', function() {
$this->comment(Inpiring::qoute());
})->purpose('Display an inpiring quote');
Shcedule::command('inspire')->hourly();
출처1: https://rezakhademix.medium.com/laravel-11-no-http-kernel-no-casts-no-console-kernel-721c62adb6ef
Laravel 11: No Http Kernel, No $casts, No Console Kernel!
Laravel 11 is scheduled for release in Q1 2024, bringing various improvements and new features to the framework.
rezakhademix.medium.com
출처2: https://laravel.com/docs/11.x/middleware#middleware-groups
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
laravel.com