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