mercredi 13 juin 2018

Laravel 5 GET api call is working but POST api calls are not working

How to disable CSRF verification on API routes in laravel?

In the API routes I am calling a function through POST and GET method. GET methord returning data's but POST method throwing method not found exception.

Here is my sample code in routes/api.php

Route::post('hellopostapi', function() {
    return json_encode( 'we are getting POST response');
});

Route::get('helloget', function() {
    return json_encode( 'we are getting GET response);
});

For GET call i am getting the response as expected. And for POST i am getting this exception

"message": "", "exception":"Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException",

"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",

"line": 255,

"trace": [
    {
        "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",

        "line": 242,

        "function": "methodNotAllowed",

        "class": "Illuminate\\Routing\\RouteCollection",

        "type": "->"
    },
    {
        "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
        "line": 176,
        "function": "getRouteForMethods",
        "class": "Illuminate\\Routing\\RouteCollection",
        "type": "->"
    },

I also added api routes in verifycsrf.php , as per documentation it should work, unfortunatly its not working for me. here is my verifiycsrf.php

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'api/*',
    ];
}

That's still not working. Can anyone please help me .Thank you



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2y7WNc9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire