[Solved] Node Js access to api laravel


You should exclude your api written in Laravel from CSRF Protection check middleware by default VerifyCsrfToken middleware is applied to route group web so here you are having two options :-

  1. Create a new middleware group named api
    code snippet for creating a middleware
    routes.php

    Route::group(['prefix' => 'api/v1','middleware' => ['api']], function () {
    Route::get('/hotel/list',[
    'uses' => 'YourController@function'
    ]);
    });

    VerifyCsrfToken.php

    protected $except = [
    'api/v1/*',
    ];

  2. Directly exclude routes for CSRF check
    In VerifyCsrfToken.php add all api’s url which you want to ignore for CSRF check

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

First method is more suggested as for all future new routes addition would work out we just need to add that route under this middleware group.

Let me know in comments if it worked out or if have any query.

1

solved Node Js access to api laravel