-2

when i hit api with post method the result this: please tell me what is problem here

strong text

[controller]

[form]

parmod
  • 25
  • 4

3 Answers3

1

This is CSRF token issue. If you want to except CSRF token on particular route then you can go on /app/Http/Middleware/VerifyCsrfToken.php

Write your route name in $except array.

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'login', 'webservice'
    ];
}
Dwarkesh Soni
  • 289
  • 3
  • 16
0

that is the CSRF token issue. if you want to run api in post method then you want to except CSRF token for api.

Remove csrf token:- goto /app/Http/Middleware/VerifyCsrfToken.php and write your route name in $except array.

like this:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

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

that will be work definitely.. :)

Ravi Thummar
  • 5,048
  • 1
  • 11
  • 22
0

this also work

app > Http > Kernel.php

and comment the same line as I did:

/**
  * The application's global HTTP middleware stack.
  *
  * @var array
  */
  protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
   //   \App\Http\Middleware\VerifyCsrfToken::class,
  ];
parmod
  • 25
  • 4
  • This is not proper way to do this. If you comment this line then CSRF token will be removed for whole routes so don't do that. – Dwarkesh Soni Jan 22 '19 at 09:06