2018-09-15 05:09:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-10-03 02:53:35 +00:00
|
|
|
use Auth;
|
2018-09-15 05:09:07 +00:00
|
|
|
use \App\User;
|
2018-09-15 05:33:21 +00:00
|
|
|
use \App\Mail\UserWaiting;
|
2018-09-15 05:09:07 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class AlertController extends Controller
|
|
|
|
{
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2018-09-19 17:58:10 +00:00
|
|
|
$item = User::loggedIn()->items()->find(request('item'));
|
2018-10-03 02:53:35 +00:00
|
|
|
$item->waiting_user_id = Auth::id();
|
2018-09-15 05:09:07 +00:00
|
|
|
$item->timestamps = false;
|
|
|
|
$item->save();
|
2018-09-15 05:33:21 +00:00
|
|
|
|
2018-10-03 02:53:35 +00:00
|
|
|
$loggedUser = Auth::user()->name;
|
2018-09-15 05:33:21 +00:00
|
|
|
$userWithItem = User::find($item->used_by);
|
2018-10-03 02:53:35 +00:00
|
|
|
\Mail::to($userWithItem)
|
|
|
|
->locale($userWithItem->language)
|
|
|
|
->send(new UserWaiting($loggedUser, $userWithItem->name, $item));
|
2018-09-15 05:33:21 +00:00
|
|
|
|
2018-09-15 05:09:07 +00:00
|
|
|
return redirect('home');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete(Request $request)
|
|
|
|
{
|
2018-09-19 17:58:10 +00:00
|
|
|
$item = User::loggedIn()->items()->find(request('item'));
|
2018-09-15 05:09:07 +00:00
|
|
|
$item->waiting_user_id = null;
|
|
|
|
$item->timestamps = false;
|
|
|
|
$item->save();
|
|
|
|
|
|
|
|
return redirect('home');
|
|
|
|
}
|
|
|
|
}
|