2018-09-15 05:09:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-10-03 02:53:35 +00:00
|
|
|
use Auth;
|
2018-10-10 03:46:28 +00:00
|
|
|
use Mail;
|
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
|
|
|
|
{
|
2018-10-10 03:46:28 +00:00
|
|
|
/**
|
|
|
|
* Store the waiting_user_id on db
|
|
|
|
* so the user can be alerted when
|
|
|
|
* the item is free
|
|
|
|
*
|
|
|
|
* @param Request $request Form data
|
|
|
|
*
|
|
|
|
* @return redirect to home
|
|
|
|
*/
|
2018-09-15 05:09:07 +00:00
|
|
|
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-10 03:46:28 +00:00
|
|
|
Mail::to($userWithItem)
|
2018-10-03 02:53:35 +00:00
|
|
|
->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');
|
|
|
|
}
|
|
|
|
}
|