cleopatra's avatar

API request error with barryvdh/Laravel-cors

I used Barryvdh Laravel-cors class to create an API endpoint for my app. I followed the following steps for that.

  1. install it using composer require barryvdh/laravel-cors

  2. updated my middleware group Route::group(['prefix' => 'api/v1', 'middleware' =>['api', 'cors'] ], function(){ Route::resource('posts', 'PostsController'); });

  3. updated config/app.php providers array with Barryvdh\Cors\ServiceProvider::class,

but i got the following error. how can i solve this??

(1/1) ReflectionException

Class cors does not exist in Container.php (line 729)

0 likes
4 replies
cleopatra's avatar

for this code in web.php in routes it is working properly. but when i add 'cors' it gives the error.

Route::group(['prefix' => 'api/zglkv10000', 'middleware' =>['api'] ], function(){ Route::resource('posts', 'PostsController'); });

ejdelmonico's avatar

Did you run php artisan vendor:publish --provider="Barryvdh\Cors\ServiceProvider"?

robrogers3's avatar

are using lumen? cause the installation is different.

Please or to participate in this conversation.