POST request from Postman to Laravel

18,303

Solution 1

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

web.php require _token the csrf field

Solution 2

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.

Share:
18,303
Irini Koutaki
Author by

Irini Koutaki

Software Developer, Mathematician

Updated on June 19, 2022

Comments

  • Irini Koutaki
    Irini Koutaki almost 2 years

    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()