Route of type POST is not working on server in Laravel

I'm trying to make a route of type post in a server but it gave me a 500 error when I do the call from POSTMAN

With routes of type get, I don't get any errors this only happens on POST

This is the error I'm getting in POSTMAN: https://www.screencast.com/t/zN6XqQxQ

This is my route

Route::post('/integrations', 'IntegrationsController@store');

This is my controller

class IntegrationsController extends Controller
{

    public function store(Request $request)
    {
        return "this route works";
    }

}

2 answers

  • answered 2021-03-03 02:12 Ryan H

    You need to return a

    new Response(‘this route works’);

  • answered 2021-03-03 03:30 omar esmaeel

    you send a post request with data without csrf token

    That what I think the issue is

    So, if that for test purposes you can temporary disable it by going to

    \app\Http\Middleware\VerifyCsrfToken.php

    add your route to this protected variable

     protected $except = [
            '/integrations'
        ];
    

    and it will work

    side note: if this endpoint is gonna be consumed only by a mobile it's not recommended to put it in the web.php route file

    instead, you can add it to api.php which will automatically remove the csrf protection because you basically don't need it

    Hope that helps