Closed dominikveils closed 6 years ago
I'm having the same problem. +1
@nerijunior as a temp solution you can change 'cors' to \Barryvdh\Cors\HandleCors::class
, it will work.
+1
I don't think its a bug. It may be how you upgraded.
I had the same error. In my case, I had the following line in my Kernel.php file
'cors' => \App\Http\Middleware\Cors::class,
However, the class App\Http\Middleware\Cors
did not exists.
After creating the following class everything worked.
<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH');
}
}
@CrestApps the problem is the OPTIONS preflight request, this simple implementation of CORS middleware do not cover the preflight.
I'm having the same problem with Laravel 5.3.30.
I added the middleware to the global middleware stack which gave me issues when I attempted to use the middleware in my routes. I had to add 'cors' => \Barryvdh\Cors\HandleCors::class,
to $routeMiddleware
and then I was able to use the middleware cors
in my routes. I'm not sure if this is related to the issues people have been having or not.
@JTallis So do I. It's quite strange because it's only me who need add cors
to routeMiddleware while other colleagues don't (and it works on their side ntw).
@tucq88. I think this issue only happened if you add ->middlewear('cors')
to your route setup. If you don't then you won't get this issue.
\Route::middleware(['cors', 'bindings'])
->namespace($this->namespace . '\Api')
->prefix('api/v1')
->group(base_path('routes/api.php'));
No, I added it in RouteProvider instead. Most strange part is everybody works ok. Only me :'(
Look in the kernel.php file for the value representing the cors key. Then, make sure that file exists in your app.
'cors' => \App\Http\Middleware\Cors::class,
After updating my project to 5.2.24 I'm getting this error: "Class cors does not exists"
I've used the
'cors'
middleware in myKernel.php
PS After changing it to
\Barryvdh\Cors\HandleCors::class
the error is disappeared, so I think the problem with thenamed
middleware: 'cors'.