Laravel 8 Disable CSRF for API requests -
Laravel 8 Disable CSRF for API requests
by on on other

Laravel 8 Disable CSRF for API requests

One thing that may get you upset while trying to make use of api through an axios request or postman is the error message with a 419 response status code. Here is a way to solve this when using laravel 8

<div class="px-4 text-lg text-gray-500 border-r border-gray-400 tracking-wider">419 </div>

<div class="ml-4 text-lg text-gray-500 uppercase tracking-wider">Page Expired </div>

The secret lies in our middle-ware settings, but sometimes we may forget or the fact that we are new to using laravel. Here is what you just simply need to do.

Locate this path in your project

app\Http\Middleware\VerifyCsrfToken.php

Open the VerifyCsrfToken.php file and scroll to wher you will see this lines of code

protected $except = [
         '/api/users'
]

Now exclude your api endpoints from there, when you exclude that, you will now be able to make those request. Please make sure to share around, Thank you :D.