I’m having trouble on some of my api calls. I was able to bypass this initial problem by using laravel cors by fruitcake –
Response to preflight request doesn’t pass access control check
But the problems didn’t stop there, some api calls threw this error
"error":"Class cors does not exist","debug":{"code":-1,"line":767,"trace":[{"file":"/home/xxxxxx/Workspace/xxxxxx/vendor/laravel/framework/src/Illuminate/Container/Container.php","line":767…]}
I was able to follow the instruction from the fruitcake/laravel-cors including adding it to kernel.php, created config/cors.php with the paths set to 'paths' => ['api/*'],
and finally adding this on my routes:
Route::group(['middleware' => 'cors'], function() {
Route::middleware('auth:api')->namespace('Api')->group(function () {
Route::middleware('admin')->prefix('admin')->namespace('Admin')->group(function() {
Route::get('dashboard/statistics', 'DashboardController@index');
...
I’m using an older version of Laravel (5.6) and PHP 7.4. Help would be much appreciated!
When I opened the endpoint on a new tab, an error appears:
Symfony Component HttpKernel Exception MethodNotAllowedHttpException No message
3
Answers
I removed the middleware on my router
to just
Add
HandleCors
class intoconfig/app.php
alias section like below.Did you run the
composer dump-autoload
command after addingHandleCors
to theconfig/app.php
?