0

I am making an API for my website, API will be used to get, post, delete some data, but to post, csrf token is needed which cannot be generated from third party websites, so I have to disable csrf token for some routes. In documentation it says to add following in verifycsrftoken.php:

protected $except = [
    'leads',
    'leads/*'
];

But this is not working in laravel 5.4. Here is my sample route:

Route::post('leads/{id}', ['as'=>'leads']);

Any help would be appreciated.

Ahmad Raza
  • 65
  • 1
  • 10

1 Answers1

1

The code you posted should work.

As you said in your comment, the error is MethodNotAllowedHttpException. That error in thrown when you try to visit a url with the wrong type. In order to send the form via POST, you will need to indicate in the form tag

<form method="POST" action="{{ url('leads/'.$lead->id) }}>

and also add the csrfToken inside the form

{!! csrf_field() !!}
Lloople
  • 1,827
  • 1
  • 17
  • 31
  • command app/Http/kernal.php in \App\Http\Middleware\VerifyCsrfToken::class no need to use csrf token – Gowthaman D Oct 23 '17 at 13:05
  • Sorry but I said im calling api from third party website, third party website cannot generate csrf tokens for my main website, and Im calling api via ajax.. – Ahmad Raza Oct 23 '17 at 13:11
  • Make sure you're calling the API from POST instead of GET then. – Lloople Oct 23 '17 at 13:15
  • resolved, i was just checking whether its working or not just by typing in the url, it was not, but using ajax, it worked... – Ahmad Raza Oct 23 '17 at 13:27
  • 1
    Typing on the URL of your browser will do the request via GET. You can check POST routes using Postman. – Lloople Oct 23 '17 at 13:28