Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Bottelet/DaybydayCRM

2311 stars
2 code files
View Bottelet/DaybydayCRM on GitHub

app/Notifications/YouWereMentionedNotification.php

Open in GitHub
use App\Models\Comment;
use Illuminate\Notifications\Notification;
 
class YouWereMentionedNotification extends Notification
{
public $comment;
 
public function __construct(Comment $comment)
{
$this->comment = $comment;
}
 
public function via($notifiable)
{
return ['database'];
}
 
public function toArray($notifiable)
{
$topic = $this->comment->commentable;
$text = __(':creator mentioned you in :topic', [
'topic' => $topic->title,
'creator' => $notifiable->name,
]);
 
$url_prefix = get_class($topic) == 'App\Models\Task' ? 'tasks/' : 'leads/';
 
return [
'assigned_user' => $notifiable->id,
'created_user' => $this->comment->user_id,
'message' => $text,
'type' => get_class($topic),
'type_id' => $topic->id,
'url' => url($url_prefix . $topic->external_id),
'action' => 'mentioned'
];
}
}

app/Listeners/NotiftyMentionedUsers.php

Open in GitHub
use App\Models\User;
use App\Events\NewComment;
use App\Notifications\YouWereMentionedNotification;
 
class NotiftyMentionedUsers
{
public function handle(NewComment $event)
{
collect($event->comment->mentionedUsers())
->map(function ($name) {
return User::where('name', $name)->first();
})
->filter()
->each(function ($user) use ($event) {
$user->notify(new YouWereMentionedNotification($event->comment));
});
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.