Upgrading Laravel 6 to 7 I have errors with barryvdh/laravel-cors

Viewed 4002

Upgrading Laravel 6.14.0 to 7 for my laravel backend app and reading this doc https://laravel.com/docs/7.x/upgrade#upgrade-7.0 I have errors with support of barryvdh/laravel-cors, as I got erorr in console:

Class 'Barryvdh\Cors\ServiceProvider' not found

If to comment 1 line In config/app.php :

//        Barryvdh\Cors\ServiceProvider::class,

and reference in app/Http/Kernel.php

I passed console commands(like config cache).

But I got CORS errors in my vue/cli app.

I tried to search in net for Barryvdh\Cors and seems here https://packagist.org/packages/barryvdh/laravel-cors there is support for laravel 7, but if installation was changed?

Also I found this https://github.com/fruitcake/laravel-cors package. Is it replacement of Barryvdh\Cors? Which steps have I to take to run my app as laravel 7?

Thanks!

2 Answers

Yes the vendor name has changed, you can find the upgrade guide here:

Upgrading from 0.x

When upgrading from 0.x versions, there are some breaking changes:

  1. The vendor name has changed (see installation/usage)
  2. Group middleware is no longer supported.
  3. A new 'paths' property is used to enable/disable CORS on certain routes. This is empty by default!
  4. The casing on the props in cors.php has changed from camelCase to snake_case, so if you already have a cors.php file you will need to update the props in there to match the new casing.

You can find the installation / usage guide here.

PS:

Laravel 5.5 and onward support package auto-discovery so you don't have to add anything into config/app.php anymore.

Yes, Laravel 7 includes first-party support for configuring Cross-Origin Resource Sharing (CORS). It looks like you will have to add the fruitcake/laravel-cors dependency. here is the CORS Support upgrade information from the Laravel documentation.

Related