Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 5 csrf_token value is Empty

Why laravel 5 csrf_token value is empty always ?

How can i get that token value ?

I tried,

  {!! csrf_token !!} , {{ csrf_token }} and 
  {{ Form::open() }} ....{{ Form::close() }}

MY OUTPUT

  <input type="hidden" name="_token"></input>
like image 411
Shankar Thiyagaraajan Avatar asked Feb 05 '16 05:02

Shankar Thiyagaraajan


2 Answers

It's because you're not using the web group middleware. Laravel is smart enough to know that if you're not using that group a token is not necessary.

Try moving your route inside the Route::group(['middleware' => 'web'] ... and tell us about it :)

Source: I made the same mistake not too long ago.

like image 78
Victor Hugo Avelar Avatar answered Sep 23 '22 14:09

Victor Hugo Avelar


Thanks to all.

Finally i find solution.

On Fresh Install:

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

Use this:

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

});

Its Working.

like image 42
Shankar Thiyagaraajan Avatar answered Sep 25 '22 14:09

Shankar Thiyagaraajan