I use these codes to stop multiple form submission.But it doesn't work. I found $form_token and $token were always the same. I had writted session(['form_token' => null]). But It doesn't work.Why?
// make token
function form_token()
{
session(['form_token' => Str::random(40)]);
return session('form_token');
}
//check token
function check_token($form_token, $token)
{
if ($form_token == $token) {
session(['form_token' => null]);
} else {
throw new RuntimeException('Do not submit multiple times');
}
}
// middleware
public function handle($request, Closure $next)
{
if (!in_array($request->method(), ['HEAD', 'GET', 'OPTIONS'])) {
$form_token = $request->input('form_token');
$token = session('form_token');
check_token($form_token, $token);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire