Fixed: 2 people were able to Take the same item at the same time

Now there is a verification before take an item.
This commit is contained in:
Bruno F. Fontes 2018-09-17 11:45:05 -03:00
parent d7af915c55
commit 15f20a6164

View File

@ -12,6 +12,9 @@ class TakeController extends Controller
public function store(Request $request) public function store(Request $request)
{ {
$item = User::find(\Auth::id())->items()->find(request('item')); $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->used_by = \Auth::id();
$item->save(); $item->save();
return redirect('home'); return redirect('home');