一、創(chuàng)建中間件設(shè)置Accept 頭
生成中間件
php artisan make:middleware AcceptHeader
設(shè)置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,
],
];