2018-09-13 00:27:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use \App\Item;
|
|
|
|
use \App\User;
|
2018-09-15 05:09:07 +00:00
|
|
|
use App\Mail\ItemAvailable;
|
2018-09-13 00:27:35 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class TakeController extends Controller
|
|
|
|
{
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$item = User::find(\Auth::id())->items()->find(request('item'));
|
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)
|
|
|
|
{
|
|
|
|
$item = User::find(\Auth::id())->items()->find(request('item'));
|
2018-09-15 05:09:07 +00:00
|
|
|
$waiting_id = $item->waiting_user_id;
|
2018-09-15 03:22:57 +00:00
|
|
|
$item->used_by = null;
|
2018-09-15 05:09:07 +00:00
|
|
|
$item->waiting_user_id = null;
|
2018-09-15 03:22:57 +00:00
|
|
|
$item->save();
|
|
|
|
|
2018-09-15 05:09:07 +00:00
|
|
|
//Send e-mail to waiting user
|
|
|
|
if ($waiting_id) {
|
|
|
|
$user = User::find($waiting_id);
|
|
|
|
\Mail::to($user)->send(
|
|
|
|
new ItemAvailable($user->name, $item)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-15 03:22:57 +00:00
|
|
|
return redirect('home');
|
|
|
|
}
|
2018-09-13 00:27:35 +00:00
|
|
|
}
|