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:
2018-09-30 21:32:33 -03:00
parent 4ec2b24885
commit 528d3b4caf
5 changed files with 99 additions and 14 deletions

View 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)
);
}
}
}