i am trying to figure out why this error even though its fresh installation.i got this error in my project so i googled ,none of the answers worked for me.so i created new project and copied all controller ,view, and model.its worked fine after few hours once again token mismatch error.why this happen in laravel ?
my form
<form class="form-horizontal action="http://localhost/laravel/public/add-post-new" enctype="multipart/form-data" method="POST" accept-charset="UTF-8" >
<div class="form-group">
<label for="inputEmail" class="control-label col-xs-2">Title</label>
<div class="col-xs-10">
<input type="text" class="form-control" id="post_title" placeholder="Title" name="post_title">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Content</label>
<div class="col-xs-10"><textarea class="form-control" style="resize:none" rows="25" name="post_content"></textarea>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Featured Image</label>
<div class="col-xs-10"><input type="file" class="filestyle" data-buttonText="Find" name="featured_image">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Post Images</label>
<div class="col-xs-10"><input type="file" class="filestyle" name="post_gallery[]" multiple />
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Select Category</label>
<div class="col-xs-10" >
<select class="form-control" name="cat_id">
<?php $data=Category::all(); ?>
<option value="0">Default Category</option>
@foreach($data as $value)
<option value="{{$value->id}}">{{$value->cat_name}}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Publish Post</label>
<div class="col-xs-10">
<label class="radio-inline">
<input type="radio" name="published" id="inlineRadio1" value="1"> Publish
</label><br>
<label class="radio-inline">
<input type="radio" name="published" id="inlineRadio2" value="2"> UnPublish
</label><br>
<label class="radio-inline">
<input type="radio" name="published" id="inlineRadio2" value="3"> Draft
</label><br><br>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Slider Post</label>
<div class="col-xs-10">
<label class="radio-inline">
<input type="radio" name="slider_post" id="inlineRadio1" value="1"> Slider Post
</label><br>
<label class="radio-inline">
<input type="radio" name="slider_post" id="inlineRadio2" value="2"> Not required
</label><br><br>
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<button type="submit" class="btn btn-primary">Submit Post</button>
</div>
</div>
before asking question i have read many tutorial
Laravel 5, Forms, TokenMismatchException in VerifyCsrfToken.php line 46
Laravel 5 Auth Post Submit - TokenMismatchException in VerifyCsrfToken.php line 46
TokenMismatchException in VerifyCsrfToken.php line 53 in Laravel 5.1
TokenMismatchException in VerifyCsrfToken.php line 46
Laravel 5, ajax, 500 Internal Server Error, TokenMismatchException in VerifyCsrfToken.php line 46:
Laravel 5 TokenMismatchException in VerifyCsrfToken.php line 46
Encountering "TokenMismatchException in VerifyCsrfToken.php" error
Laravel TokenMismatchException
http://laravel.io/forum/01-30-2015-laravel5-tokenmismatchexception-in-verifycsrftoken
This may help someone. Check your php files that not start with empty line or space! It cost me much trouble. Including that above!
Suddenly I am getting this exception.
Then restarting and clean cache works for me.
To clear the cache use :
php artisan cache:clear
I had this painful error and this is what I did to fix it: 1. Go to
\Http\Controllers\Middleware\VerifyCsrfToken.php
2. In theprotected $except
add your route to be excluded from this verification. Example:And if you still get this error, add this function below the protected $except
}
And I think that's it. I hope to help someone.
try adding this line after opening a form