合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
先创建一个中间件 php artisan make:middleware AcceptHeader ~~~ <?php namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; class AcceptHeader { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next) { $request->headers->set('Accept', 'application/json'); return $next($request); } } ~~~ ~~~ namespace App\Http\Kernel.php ~~~; ~~~ ![](https://img.kancloud.cn/f8/83/f883c8d952662fbbf95a7fd8b6f830c1_933x84.png)