0

i am new to both laravel 5 and Angular Js, all i want to do is post a simple form to the server, nothing else, just that, but i get errors when i try, i read around and saw that it had something to do with csrf token security. I found an answer on stack overflow: how-to-send-csrf-token-inside-angularjs-form-using-laravel-api that is the last answer, now what happens is i do get a token when my page loads but when i ty to post data i get an error because for some reason the tokens do not match. In laravel 4 i did not really deal directly with csrf since i was not using a front-end framework and was using the form generator.

This is all so new and difficult for me, is there a simpler, working example i can try, is there an available class that can make all this easier for me? Thank you in advance.

Community
  • 1
  • 1
user3718908x100
  • 7,939
  • 15
  • 64
  • 123

1 Answers1

0

You can do it by adding hidden _token field to the form:

<input type="hidden" name="_token" value="{{ csrf_token(); }}">

After that add a filter to your route:

Route::post('register', array('before' => 'csrf', function()
{
    return 'You gave a valid CSRF token!';
}));
Raviraj Chauhan
  • 655
  • 5
  • 7