laravel api设置Accept 头

一、创建中间件设置Accept 头

生成中间件

php artisan make:middleware AcceptHeader

设置Accept头

headers->set('Accept', 'application/json');
        return $next($request);
    }
}

将中间件添加到api中间件组中

protected $middlewareGroups = [
        'web' => [
       .
       .
       .
        ],
        'api' => [
            \App\Http\Middleware\AcceptHeader::class,
            'throttle:60,1',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

你可能感兴趣的:(laravel api设置Accept 头)