Laravel 5.2 : csrf token doesn't work
Hi Why my csrf token value is null ? And when i don't use token i havent TokenMismatchException!!!! how can i fix it ?
I dug deeper and found that a session is not being registered in SessionServiceProvider. Is there something that needs to be enabled for this to work by default? Since I am a Laravel beginner, I am not sure how to follow the advice above. How do I make sure that my routes are added under the "web" group?
<form method="post" action="<?php echo url('/form'); ?>">
<input type="hidden" name="_Token" value="{{ csrf_token() }}">
<input type="text" name="Title" placeholder="Title"><br>
<textarea rows="10" name="Content" placeholder="Content"></textarea><br>
<input type="submit" value="Send">
</form>
Answer
Make sure your route has the web milddleware applied to it.
Pretty much any route where you will want sessions, csrf protection, encrypted cookies, session errors, etc ... you will need the 'web' middleware group applied.
Check your routes.php file for the route group like so:
Route::group(['middleware' => 'web'], function () {
//
});
Update: Since 5.2.27 The RouteServiceProvider
now puts all your routes in routes.php
in a route group that has the web
middleware applied for you.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?