-
app/Notifications/MentionedUser.php
Open in GitHubuse App\Comment; use App\User; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; class MentionedUser extends Notification { public function __construct(Comment $comment, User $user) { $this->comment = $comment; $this->user = $user; } public function via($notifiable) { return ['mail', 'database']; } public function toMail($notifiable) { $message = (new MailMessage()) ->subject('['.$this->comment->discussion->group->name.'] '.trans('messages.you_have_been_mentionned_by').' '.$this->user->name) ->line(trans('messages.you_have_been_mentionned_by').' '.$this->user->name.' '.trans('messages.in_the_discussion').' '.$this->comment->discussion->name.' : ') ->line(html_entity_decode(strip_tags(filter($this->comment->body)))) ->action(trans('messages.reply'), route('groups.discussions.show', [$this->comment->discussion->group, $this->comment->discussion])) ->line(trans('messages.dont_reply_to_this_email')); if ($this->comment->discussion->inbox()) { $message->from($this->comment->discussion->inbox(), $this->comment->discussion->group->name); } else { $message->from(config('mail.noreply'), config('mail.from.name')); } return $message; } }
-
app/Listeners/NotifyMentionedUsers.php
Open in GitHubuse Notification; class NotifyMentionedUsers { public function handle(ContentCreated $event) { if ($event->model instanceof Comment) { $comment = $event->model; $users = $this->findUsers($comment->body); foreach ($users as $user) { if ($user->isMemberOf($comment->discussion->group)) { Notification::send($user, new \App\Notifications\MentionedUser($comment, \Auth::user())); flash($user->name . ' ' . trans('messages.notified')); } } } } // }
-
app/Providers/EventServiceProvider.php
Open in GitHubuse Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { protected $listen = [ 'App\Events\ContentCreated' => [ 'App\Listeners\NotifyMentionedUsers', ], ]; // }