Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel cors "Class cors does not exist" error

I have followed https://github.com/barryvdh/laravel-cors to enable CORS on my application.

When I refresh my page (REST endpoint), I get the following message :-

Class cors does not exist

I ran the following command :-

composer require barryvdh/laravel-cors 0.7.x

and have the following line in my composer.json

"barryvdh/laravel-cors": "0.7.x"

Routes.php

Route::group(['middleware' => 'cors'], function($router){
    $router->get('names/{id}', 'NameController@showEmpDetail');
    $router->resource('names', 'NameController');
});

I am guessing that somewhere I'll need to call the package, like use the package etc..but I am not finding any result to help me out.

Please help.

Thanks

like image 665
Stacy J Avatar asked Dec 03 '22 16:12

Stacy J


1 Answers

Try to add

 'cors' => \Barryvdh\Cors\Middleware\HandleCors::class,

to

 /app/Http/Kernel.php $routeMiddleware
like image 58
Syrok Avatar answered Dec 24 '22 13:12

Syrok