mercredi 31 août 2016

Can't delete session value in laravel5.2

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);
    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bId1ub
via IFTTT

Aucun commentaire:

Enregistrer un commentaire