API request error with barryvdh/Laravel-cors

Published 11 months ago by cleopatra

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)


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'); });


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


are using lumen? cause the installation is different.

Please sign in or create an account to participate in this conversation.