0

I'm using Laravel 6 and php 7 along with ReactJS. I'm following Build a Basic CRUD App with Laravel and React tutorial to learn how to make a CRUD app. In the tutorial, it says that I need to enable CORS so the API can be accessed from the front-end application. After I install the barryvdh cors by running:

composer require barryvdh/laravel-cors

and add it to my Kernel.php:

protected $middlewareGroups = [
    'web' => [
        ...
        \Barryvdh\Cors\HandleCors::class,
    ],

    'api' => [
        ...
        \Barryvdh\Cors\HandleCors::class,
    ],
];

the class is still undefined in Laravel and I get the error shown here

Here is a screenshot of my code.

Does anyone know how to solve this issue?

fubar
  • 16,918
  • 4
  • 37
  • 43
Aufa
  • 3
  • 1

1 Answers1

0

It looks like you're using an out of date tutorial. If you Google for barryvdh/laravel-cors, you'll see that the repository has been renamed to fruitcake/laravel-cors.

composer require fruitcake/laravel-cors

I suspect that the dependency therefore didn't install, or if it did, that you're referencing the incorrect namespace. It should be:

\Fruitcake\Cors\HandleCors::class
fubar
  • 16,918
  • 4
  • 37
  • 43