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 :-
-
Create a new middleware group named
api
code snippet for creating a middleware
routes.phpRoute::group(['prefix' => 'api/v1','middleware' => ['api']], function () {
Route::get('/hotel/list',[
'uses' => 'YourController@function'
]);
});VerifyCsrfToken.php
protected $except = [
'api/v1/*',
]; -
Directly exclude routes for CSRF check
InVerifyCsrfToken.phpadd all api’s url which you want to ignore for CSRF checkclass 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