%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/news/app/Observers/
Upload File :
Create Path :
Current File : /var/www/html/news/app/Observers/CommentModelObserver.php

<?php


namespace App\Observers;


use App\Models\Comment;
use App\Models\Notification;
use App\Models\User;
use App\Notifications\SendMailForInappropriateComment;

class CommentModelObserver
{
    /**
     * Listen to the User created event.
     *
     * @param Comment $comment
     * @return void
     */
    public function created(Comment $comment)
    {
        if (!$comment->isAppropriate()) {
            $notification = Notification::query()->where('code', 'inappropriate_comment_added')->first();
            if ($notification->send_notification_flag) {
                $comment->article->creator->notify(new SendMailForInappropriateComment($comment->article->creator, $notification, $comment->article));
                $administrators = User::query()->whereHas('roles', function ($query) {
                    $query->where('slug', User::ROLE_SLUG_ADMIN);
                })->get();
                foreach ($administrators as $admin) {
                    if ($comment->article->creator->id !== $admin->id) {
                        $admin->notify(new SendMailForInappropriateComment($admin, $notification, $comment->article));
                    }
                }
            }
        }
    }
}

Zerion Mini Shell 1.0