【Laravel】artisanのmake:middlewareコマンドを解説

Laravel

Laravel 10.xのartisanの「make:middleware」コマンドを解説します。

Description

新しいミドルウェアクラスの作成

Usage

php artisan make:middleware [--test] [--pest] [--] <name>

Arguments

引数必須説明
name必須ミドルウェア名

Options

オプション省略形必須説明
test--Middlewareに付随するPHPUnitのテストを生成
pest--ミドルウェアに付随するPestテストを生成

Examples

no options

php artisan make:middleware Foo
   INFO  Middleware [app/Http/Middleware/Foo.php] created successfully.  
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class Foo
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        return $next($request);
    }
}

Follow me!

コメント

PAGE TOP
タイトルとURLをコピーしました