I built an API with Laravel and while trying to make a get request via URL localhost8000/api/items
I built a CORS middleware.
<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers','Content-Type, Authorization, X-XSRF-TOKEN');
}
}
When trying to access data via API, localhost:8000/api/items
, I get the following URL on my Laravel terminal and
Call to undefined method Symfony\Component\HttpFoundation\Response::header()
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire