laravel Api Resource. Delete Request Session expired. Only Get method Working

Viewed 620

Eloquent: API Resources I am Trying to Crud a table using POSTMAN and laravel Api Resources. ] Although using get method i can get all the data. When i use delete or post method, it returns an error of session expired. Thanks in advance.Image Of POSTMAN

Image of routes

2 Answers

Sounds like you're missing the CRSF token, which would explain why HTTP GET's are working. One option to work around this is to disable the CSRF middleware when working in your development environment. Simplest solution is to open up app/Http/Middleware/VerifyCsrfToken.php and set:

protected $except = [
    '*',
];

The * is a wildcard-like option that will disable CSRF verification for all routes. Obviously ideal solution would to be to disable it on a higher level only when working on local development, but the provided answer is a quick solution.

See the Laravel documentation on CSRF Excluding URI's

Sorry for the trouble. I found the problem,actually i was posting the routes in web.php instead of api.php . That was why i was getting the errors. Thankyou for the concern.

Related