How to send csrf_token() inside AngularJS form using Laravel API?

后端 未结 5 997
面向向阳花
面向向阳花 2020-11-28 07:16

I am trying to build an angular + laravel rest application. I can get the views of my database. When I try to add new items. I get 500 error telling me mismatch

5条回答
  •  执念已碎
    2020-11-28 07:56

    An option will be to inject the CSRF token as a constant. Append the following in your head tag:

    
    

    Then in your module methods it can be injected when needed.

    app.factory("FooService", function($http, CSRF_TOKEN) {
        console.log(CSRF_TOKEN);
    };
    

    Maybe you will be interested of peeking at the source code of this sample Laravel + AngularJS project.

提交回复
热议问题