Dragos Strugar Dragos Strugar - 1 year ago 62
PHP Question

Executing Post request in Laravel gives TokenMismatchException

I have a

model with title and content attributes. I also have views that display all notes (index) and specific note (show). That works fine.
Now I was about to create a form and create Notes from the form, and there was an error:
TokenMismatchException in VerifyCsrfToken.php line 67:
Here is my Routes file:

Route::get('/notes', 'NotesController@index');
Route::get('notes/{note}', 'NotesController@show');

Route::post('/notes', 'NotesController@create');

My controller is on Gist.

And my view.

How can I get rid of this error, and what is causing it?

mmm mmm
Answer Source

Add a hidden input field

<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"/>

and have a look at laravel's documentation

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download