0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Laravel11】Laravelの新しいMiddlewareの登録方法

Posted at

最近の Laravel って Middleware の登録の仕方変わったんだね...

スクリーンショット 2024-10-17 14.47.26.png

$ sail artisan make:middleware TestMiddleware

app/Http/Middleware/TestMiddleware.php に生成される

グローバルに登録するときは、bootstrap/app.php に登録する

bootstrap/app.php
    ->withMiddleware(function (Middleware $middleware) {
        // グローバル共通ルートの先頭に登録
        $middleware->prepend(AutoTransaction::class);
        // グローバル共通ルートの末尾に登録
        $middleware->append(AutoTransaction::class);

        // Webルートの末尾に追加
        $middleware->web(append: [
            AutoTransaction::class,
        ]);

        // APIルートの先頭に追加
        $middleware->api(prepend: [
            AutoTransaction::class,
        ]);
    })

他にも既存の Middleware の置き換え、グループ化、優先度など、メソッドは豊富に用意されているので、以前よりは楽になったのかもしれない?

おわり

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?