mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-23 20:10:52 +00:00
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:
parent
d7af915c55
commit
15f20a6164
@ -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');
|
||||||
|
Loading…
Reference in New Issue
Block a user