F
F
fashionmens2020-01-29 14:23:31
Laravel
fashionmens, 2020-01-29 14:23:31

Why might $except in \Middleware\VerifyCsrfToken not work in Laravel?

routes/web.php has this code

Route::match(['get','post'], '/api', 'Api\[email protected]');

Controller
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ApiController extends Controller
{
    public function index(Request $request) {
echo '123';
    }

In VerifyCsrfToken
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
    protected $except = [
        '/api'
    ];
}

But for some reason a GET request opens a route. And the post gives an error.
What could be? where to dig?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zorca, 2020-01-29
@zorca

Check the list of routes with the command: php artisan route:list, if the required route does not exist, try resetting the router's cache.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question