一、创建中间件设置Accept 头
生成中间件
php artisan make:middleware AcceptHeader
设置Accept头
<?php
namespace App\Http\Middleware;
use Closure;
class AcceptHeader
{
public function handle($request, Closure $next)
{
$request->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,
],
];