Help us understand the problem. What is going on with this article?

【Laravel】ミドルウェア(Middleware)で任意のパラメータを渡す。

メモとして残します。

■やり方

ミドルウェア呼び出し側

下記の例ではルーティングでミドルウェアを呼び出しているが、基本的には変わらない(はず)

//複数の場合、第二パラメータ以降はカンマで区切る
Route::middleware('my_middleware:引数1,引数2')->group(function () {

});

ミドルウェア(my_middleware)側

ミドルウェアの第二引数$nextの次に任意のパラメータを入れる引数を定義する。

namespace App\Http\Middleware;
use Closure;
class MyMiddleware
{
    public function handle($request, Closure $next, $arg1="", $arg2="")
    {
        //$arg1=引数1
        //$arg2=引数2
        return $next($request);
    }
}

msht0511
Webエンジニアです。 主に役に立ったスキルを備忘録として投稿してます。 基本的に自分用のメモです。。 エンジニアですがニホン言語は苦手です。。。。
https://lapras.com/public/WAWLBKV
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした