2018-09-13 00:27:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use \App\Item;
|
|
|
|
use \App\User;
|
|
|
|
use Illuminate\Http\Request;
|
2018-10-01 00:32:33 +00:00
|
|
|
use App\Events\ReturnItem;
|
2018-09-13 00:27:35 +00:00
|
|
|
|
|
|
|
class TakeController extends Controller
|
|
|
|
{
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2018-09-19 17:58:10 +00:00
|
|
|
$item = User::loggedIn()->items()->find(request('item'));
|
2018-09-17 14:45:05 +00:00
|
|
|
if ($item->used_by) {
|
2018-09-27 16:00:03 +00:00
|
|
|
return back()->withErrors(
|
|
|
|
\Lang::getFromJson(
|
|
|
|
"This item is already taken"
|
|
|
|
)
|
|
|
|
);
|
2018-09-17 14:45:05 +00:00
|
|
|
}
|
2018-09-14 15:52:07 +00:00
|
|
|
$item->used_by = \Auth::id();
|
2018-09-13 00:27:35 +00:00
|
|
|
$item->save();
|
|
|
|
return redirect('home');
|
|
|
|
}
|
2018-09-15 03:22:57 +00:00
|
|
|
|
|
|
|
public function delete(Request $request)
|
|
|
|
{
|
2018-09-19 17:58:10 +00:00
|
|
|
$item = User::loggedIn()->items()->find(request('item'));
|
2018-10-01 00:32:33 +00:00
|
|
|
event(new ReturnItem($item));
|
|
|
|
$item->returnItem();
|
2018-09-15 03:22:57 +00:00
|
|
|
return redirect('home');
|
|
|
|
}
|
2018-09-13 00:27:35 +00:00
|
|
|
}
|