Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST request from Postman to Laravel

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

like image 283
Irini Koutaki Avatar asked Sep 02 '17 09:09

Irini Koutaki


People also ask

How to use postman with Laravel API to Postman?

Laravel API to Postman is a package by Andreas Elia that allows you to automatically generate a Postman collection based on your app’s API routes. After you install the package, you can run the following artisan command, which will automatically generate a postman collection by introspecting your app’s API routes: 1 php artisan export:postman

What is a POST request in Laravel?

When we send a POST request we generally intend to have some modification at the server such as updation, deletion or addition. One of the classic example of a POST request is the Login page.

How do I generate a postman collection from an API route?

After you install the package, you can run the following artisan command, which will automatically generate a postman collection by introspecting your app’s API routes: Postman is a popular API development GUI that simplifies building and testing APIs.

How to perform HTTP requests with Laravel HTTP client?

To perform HTTP requests with Laravel Http Client you can directly import and use the facade right away like below. The Http facade comes with "get", "post", "put", "patch" and "delete" methods as follows.


1 Answers

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

web.php require _token the csrf field

like image 55
Niklesh Raut Avatar answered Sep 20 '22 00:09

Niklesh Raut