File: /home/imensosw/www/mpl.imenso.co/app/Listeners/SendVenueNewChallengeNotification.php
<?php
namespace App\Listeners;
use App\Events\PromoterCreatesChallenge;
use App\Models\Notification;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\Facades\View;
class SendVenueNewChallengeNotification
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param ArtistRecommendsArtist $event
* @return void
*/
public function handle(PromoterCreatesChallenge $event)
{
if (isset($event->enquiry->promoter)) {
$html = view('notifications/venue/new-challenge')->with([
'enquiry' => $event->enquiry,
])->render();
$notification = $event->enquiry->venue->addNotification(
101,
$html,
[
'enquiry' => $event->enquiry->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/venue/new-challenge')->with([
'enquiry' => $event->enquiry,
])->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->enquiry->venue->id,
],
'notification',
$data
);
}
}
}
}