From 15f20a61646806b4d3587fd0c8ba0446ae549498 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Mon, 17 Sep 2018 11:45:05 -0300 Subject: [PATCH] Fixed: 2 people were able to Take the same item at the same time Now there is a verification before take an item. --- app/Http/Controllers/TakeController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Http/Controllers/TakeController.php b/app/Http/Controllers/TakeController.php index 05ffec0..1b62c7c 100644 --- a/app/Http/Controllers/TakeController.php +++ b/app/Http/Controllers/TakeController.php @@ -12,6 +12,9 @@ class TakeController extends Controller public function store(Request $request) { $item = User::find(\Auth::id())->items()->find(request('item')); + if ($item->used_by) { + return back()->withErrors("This item is already taken"); + } $item->used_by = \Auth::id(); $item->save(); return redirect('home');