Answer the question
In order to leave comments, you need to log in
Why is csrf_token() empty on Laravel 5.2?
Hello!
I don’t understand why, when trying to create a form, csrf_token is empty?
I am using Laravel 5.2.44
Form:
{!! Form::open((array('action' => '[email protected]'))) !!}
<input type="text" name="name" id="name">
<button type="submit">Submit</button>
{!! Form::close() !!}
<form method="POST" action="http://cms.local/contact" accept-charset="UTF-8"><input name="_token" type="hidden">
<input type="text" name="name" id="name">
<button type="submit">Submit</button>
</form>
Route::group(['middleware' => 'web'], function () {
Route::post('contact', ['as' =>'contact','uses' => '[email protected]']);
Route::get('bar', function () {
return csrf_token(); // works
});
});
public function store(Request $request)
{
$input = Request::all();
return $input;
}
Answer the question
In order to leave comments, you need to log in
Thanks to all who are not indifferent)))
I found a mistake. It turned out that I messed up in RouteServiceProvider and did not use web middleware for its class
Now I fixed it:
protected function mapWebRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'web',
], function ($router) {
require app_path('Http/routes.php');
foreach (Page::all() as $page){
$router->get($page->url, ['as' => $page->name, function () use ($page,$router){
return $this->app->call('LH\Http\Controllers\[email protected]',[
'page' => $page,
'parameters' => $router->current()->parameters()
]);
}]);
}
});
}
Hey!
Maybe it will help:
1) stackoverflow.com/questions/34422751/why-is-my-csr...
2) Why does csrf_token() return null on Laravel 5.2?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question