File: /home/imensosw/www/mpl.imenso.co/app/Listeners/SendArtistRecommendedYouNotification.php
<?php
namespace App\Listeners;
use App\Events\ArtistRecommendsArtist;
use App\Models\Notification;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\Facades\View;
class SendArtistRecommendedYouNotification
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param ArtistRecommendsArtist $event
* @return void
*/
public function handle(ArtistRecommendsArtist $event)
{
$html = view('notifications/artists/artist-recommended-you')->with([
'recommender' => $event->recommender,
'recommendee' => $event->recommendee,
])->render();
$notification = $event->recommendee->addNotification(
201,
$html,
[
'recommender_id' => $event->recommender->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/artists/artist-recommended-you')->with([
'recommender' => $event->recommender,
'recommendee' => $event->recommendee,
])->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->recommendee->id,
],
'notification',
$data
);
}
}
}