devaslanphp / project-management

An open source Project management tool based on Laravel and Filament
https://devaslanphp.github.io/project-management
MIT License
681 stars 188 forks source link

Mails will be send to all users in a project #106

Closed HeldvonKosmos closed 6 months ago

HeldvonKosmos commented 6 months ago

Hey there, thank you for the wonderful WebApp. It is the one thing that makes my life much easier at this moment. I have only one problem. The Mails will be send to every user that is in a project. It would be much better to send only to users, that have subscribed to a ticket. Thanks in advance.

HeldvonKosmos commented 6 months ago

I have solved the problem. Just modify the function watchers() from Line 146 in /app/Models/Ticket.php as follows:

public function watchers(): Attribute
{
    return new Attribute(
        get: function () {
            $users = collect();
            $users->push($this->owner);
            if ($this->responsible) {
                $users->push($this->responsible);
            }

            $subscribers = TicketSubscriber::where('ticket_id', $this->id)->get();
            foreach ($subscribers as $subscriber) {
                $users->push($subscriber->user);
            }

            return $users->unique('id');
        }
    );
}