7
votes

I am trying to send a post request to a Laravel project using Postman, but I get a "419 unknown status" response

routes\web.php:

Route::post('/myaction', 'MymodelController@myaction');

app\Http\Controllers\MymodelController.php:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Mymodel;

class MymodelController extends Controller
{
    function myaction()
    {
        return redirect('/');
   }
}

Why does this happen?

The same error appears independently of the content of myaction()

3
The csrf? No, how can I send it through Postman?Irini Koutaki
Thank you! The solution was to use api.php instead of web.php. (Please write it as a reply, for further help to other viewers)Irini Koutaki

3 Answers

11
votes

As you are requesting api you should write your route in api.php instead web.php

web.php require _token the csrf field

2
votes

By default, Laravel use the middleware VerifyCsrfToken. See this for more details.

You need to add your URL to the $excludes field inside VerifyCsrfToken class.

0
votes

Do you have defined route for redirect('/'); in web.php ?