D
D
Dauren Bablan2016-02-29 20:31:07
CSRF
Dauren Bablan, 2016-02-29 20:31:07

Why does the csrf_token() function return null?

Good day! Can someone tell me why in the template, the csrf_token () function does not display anything. In Laravel 5. I can not understand, maybe someone has already encountered a similar problem. Tell. thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tesla, 2016-03-01
@Tesla

If Laravel 5.2, then you need to add ['middleware' => 'web']to the route:

Route::get('foo', function () {
    return csrf_token(); // null
});

Route::group(['middleware' => 'web'], function () {
    Route::get('bar', function () {
        return csrf_token(); // works
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question