mirror of
https://github.com/brunofontes/shareit.git
synced 2025-11-15 16:00:54 -03:00
Refactoring: TakeController returned item Mail moved to a listener
The TakeController was manually sending the email message as well as dealing with item return, so I moved the email message to it's own listener, I created an event for it and moved the return part to the item model.
This commit is contained in:
@@ -4,8 +4,8 @@ namespace App\Http\Controllers;
|
||||
|
||||
use \App\Item;
|
||||
use \App\User;
|
||||
use App\Mail\ItemAvailable;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Events\ReturnItem;
|
||||
|
||||
class TakeController extends Controller
|
||||
{
|
||||
@@ -27,19 +27,8 @@ class TakeController extends Controller
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$item = User::loggedIn()->items()->find(request('item'));
|
||||
$waiting_id = $item->waiting_user_id;
|
||||
$item->used_by = null;
|
||||
$item->waiting_user_id = null;
|
||||
$item->save();
|
||||
|
||||
//Send e-mail to waiting user
|
||||
if ($waiting_id) {
|
||||
$user = User::find($waiting_id);
|
||||
\Mail::to($user)->send(
|
||||
new ItemAvailable($user->name, $item)
|
||||
);
|
||||
}
|
||||
|
||||
event(new ReturnItem($item));
|
||||
$item->returnItem();
|
||||
return redirect('home');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user