Skip to content

[7.x] Fix SendQueuedNotifications notifiables property type #31675

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

Merged
merged 2 commits into from
Mar 2, 2020
Merged

[7.x] Fix SendQueuedNotifications notifiables property type #31675

merged 2 commits into from
Mar 2, 2020

Conversation

axlon
Copy link
Contributor

@axlon axlon commented Mar 2, 2020

Currently the notifiables property is typehinted as a collection, but it isn't actually (always) one. For instance when doing $request->user()->notify(new MyNotification), the notifiables property will be set to an instance of App\User.

For the sending of the notifications it does not seem to matter if its actually a collection or not, so I opted to always wrap a collection around the given notifiable(s); this allows for collection operations in notification middleware without having to do type checks.

For example:

public function handle($job, $next)
{
    if ($job->notifiables->isNotEmpty()) {
        // do something...
    }
}

Side note: I didn't know which version to target this to, because technically it's not working correctly at the moment, but I can also see this breaking people's code if they are using notification middleware.

@taylorotwell taylorotwell merged commit b7b55d0 into laravel:7.x Mar 2, 2020
@axlon axlon deleted the queued-notifications-notifiables-collection branch March 2, 2020 20:17
@driesvints
Copy link
Member

driesvints commented Mar 20, 2020

@axlon this seems to have lead to issues regarding model serialization: #32039

@axlon
Copy link
Contributor Author

axlon commented Mar 20, 2020

@driesvints Should we wrap it in an Eloquent collection when its a model? This would conform to the typehint and should also fix serialization

Another option would be to check for \Illuminate\Contracts\Queue\QueueableCollection, and if it is don't wrap, although this technically doesn't ensure that its actually a subclass of Collection.

The changes could also be reverted, but this would not have my preference because that could break people's projects

@driesvints
Copy link
Member

@axlon if that fixes the problem then yes definitely.

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.

3 participants