I faced a problem with Laravel 5.4 in POST routes.
When the form submitted, the error TokenMismatchException was shown.
I thought it was about PrefixVariable so I opened this issue on Github. But after testing too much and trying different solutions, I've figured out that the problem wasn't made by Prefix.
Everything in Firefox is OK, the main problem occurs in chrome. The Post routes only work once, after submitting the first form, all the next requests to same URL face TokenMismatchException error.
I've tried followings:
- Clearing Chrome cookies and history
- Running
php artisan cache:clear
command - Changing Serve port
- Prevent caching in PHP with headers
- Prevent caching in HTML with Meta Tags
But the problem still exists.
What's wrong exactly?! It would be appreciated if you help me.
Login Form:
<form method="post" action="{{route('login')}}">
{!! csrf_field() !!}
<div class="row">
<div class="col-xs-12">
<div class="form-group no-margin">
<div class="col-xs-6 col-md-10 col-md-offset-1">
<input name="username" type="text" class="form-control" placeholder="نام کاربری" value="{{old('username')}}">
</div>
</div>
<div class="form-group no-margin">
<div class="col-xs-6 col-md-10 col-md-offset-1">
<input name="password" type="password" class="form-control" placeholder="کلمه عبور">
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group no-margin">
<div class="col-xs-5 col-md-offset-1">
<input name="captcha" type="text" class="form-control" placeholder="کپچا">
</div>
<div class="col-xs-5 no-pad-right">
<img src="{{captcha_src('flat')}}" class="img-responsive">
</div>
</div>
</div>
<div class="col-xs-12 text-center">
<div class="form-group">
<button type="submit" class="btn btn-success btn-raised">ورود<div class="ripple-container"></div></button>
<button type="reset" class="btn btn-danger btn-raised">انصراف<div class="ripple-container"></div></button>
</div>
</div>
</div>
</form>
web.php
Route::group(['prefix' => config('system.ADMIN_PATH'), 'namespace' => 'Panel'], function(){
Route::get('/', function(){return redirect()->route('login');});
Route::get('/auth', 'AuthController@Login')->name('login');
Route::post('/auth', 'AuthController@Auth')->name('check');
});
AuthController.php:
namespace App\Http\Controllers\Panel;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class AuthController extends Controller
{
public function Login(Request $request)
{
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
return view('admin.login');
}
public function Auth(Request $request)
{
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
dump($request->all());
echo "Received";
}
}