I have also tried this way of doing it and still have the same issue (2 requests at least go through successfully.)
$lock = Cache::lock('withdraw_bank_' . Auth::id(), 10);
try {
$lock->block(5);
$user = Auth::user();
$validate = $request->validate([
'withdrawal' => ['integer', 'min:0', 'max:' . $user->bank_balance, function($attribute, $value, $fail) use ($user) {
if($user->times_withdrawn >= 15) {
$fail('You\'ve already withdrawn enough times today!');
}
}]
]);
$user->bank_balance -= $request->post('withdrawal');
$currency_control->addCurrency(Auth::user(), 1, $request->post('withdrawal'));
$user->times_withdrawn++;
$user->save();
return redirect()->back();
} catch (LockTimeoutException $e) {
return redirect()->back()->withErrors(['withdrawal' => 'Moving too quickly for the bank teller to properly help you. Slow down.']);
} finally {
optional($lock)->release();
}
If anyone needs any more information (like laravel ver, php ver, etc...) just ask. I'm new to the whole asking for help via forums I'm just kind of desperate to fix this.