File: /home/imensosw/www/mpl.imenso.co/app/Listeners/SendFanFriendRequestedYouNotification.php
<?php
namespace App\Listeners;
use App\Events\FanFriendRequestsFan;
use App\Models\Notification;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\Facades\View;
class SendFanFriendRequestedYouNotification
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param FanFriendRequestsFan $event
* @return void
*/
public function handle(FanFriendRequestsFan $event)
{
$html = view('notifications/fan/fan-friend-requested-you')->with([
'requester' => $event->requester,
'requestee' => $event->requestee,
])->render();
$notification = $event->requestee->addNotification(
301,
$html,
[
'requester_id' => $event->requester->id,
]
);
if ($notification) {
$html = '<a href="javascript: void(0)" onclick="clearNotification('.$notification->id.')" class="clear-btn"><i class="fa fa-close"></i></a>';
$html .= Notification::parseNotification(
view('notifications/fan/fan-friend-requested-you')->with([
'requester' => $event->requester,
'requestee' => $event->requestee,
])->render()
);
$html .= '<div class="time-ago">'.$notification->created_at->diffForHumans().'</div>';
if ($notification->getActions()) {
$html .= '<div class="action-row">'.$notification->getActions().'</div>';
}
$data = [
'action' => 'add-notification',
'html' => $html,
'id' => $notification->id,
];
Broadcast::broadcast(
[
'private-user_'.$event->requestee->id,
],
'notification',
$data
);
}
}
}