Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make $notification available in routeNotificationForFcm #26

Merged
merged 2 commits into from
Oct 17, 2018
Merged

Make $notification available in routeNotificationForFcm #26

merged 2 commits into from
Oct 17, 2018

Conversation

chimit
Copy link
Contributor

@chimit chimit commented Oct 12, 2018

No description provided.

@benwilkins
Copy link
Owner

Why do you need $notification here? The notifiable entity should just be determining where the notification is going, which shouldn't be dependent on the notification itself. Also, this would present breaking changes.

@chimit
Copy link
Contributor Author

chimit commented Oct 17, 2018

Because $notification is available in other delivery channels. In my case, I need it to filter recipients:

class Group extends Model
{
    use Notifiable;

    public function users()
    {
        return $this->belongsToMany('App\Models\User')
                    ->withTimestamps();
    }

    public function routeNotificationForFcm($notification)
    {
        return $this->load(['users' => function ($query) use ($notification) {
            // Do not send push notification to the author
            $query->where('users.id', '<>', $notification->user->id);
        }, 'users.devices'])
            ->users
            ->pluck('devices')
            ->collapse()
            ->pluck('fcm_token')
            ->all();
    }
}

I send notifications to groups of users instead of users to prevent multiple requests to the Firebase. Related to this issue: #2

@benwilkins
Copy link
Owner

I'll approve it. It will have to be version 3.0 since it introduces breaking changes.

@benwilkins benwilkins merged commit a184c3e into benwilkins:master Oct 17, 2018
@chimit chimit deleted the patch-2 branch October 18, 2018 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants