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:
40
app/Listeners/AlertReturnedItem.php
Normal file
40
app/Listeners/AlertReturnedItem.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Mail;
|
||||
use App\User;
|
||||
use App\Events\ReturnItem;
|
||||
use App\Mail\ItemAvailable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class AlertReturnedItem
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email to the user that
|
||||
* is waiting for the item
|
||||
*
|
||||
* @param ReturnItem $item
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ReturnItem $event)
|
||||
{
|
||||
if ($event->item->waiting_user_id) {
|
||||
$user = User::find($event->item->waiting_user_id);
|
||||
Mail::to($user)->send(
|
||||
new ItemAvailable($user->name, $event->item)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user