laravellumen

CSRF Protection in Lumen, Exception From Helper Function


According to the documentation for Laravel Lumen, it's possible to make use of the CSRF helper function to generate a CSRF token. However, when I go ahead and use the csrf_field function or the csrf_token function, I am presented with an error message:

Call to undefined function csrf_field()

and

Call to undefined function csrf_token()

respectively.

Research

It would appear as though some people are saying CSRF protection is not a part of Lumen, but since it's listed by the documentation I'd assume it is.

It's fairly possible I've overlooked something rather simple. Do I somehow need to tell Lumen that I'd like to use this helper specifically? Anyhow, any pointers in the right direction would be very much appreciated!


Solution

  • Lumen doesn't have these helpers. You can check it by yourself by looking into the source code. So, you'll need to insert token manually:

    <input type="hidden" name="_token" value="{{ app('session')->token() }}">