[12.x] Preserve notification state mutations from via() in sendNow()#58558
Conversation
|
My gripe is with the example choice when the documented way to set a notification's locale based on the notifiable is to make the notifiable implement the Reference: https://laravel.com/docs/12.x/notifications#user-preferred-locales I am not sure if a notification should be mutated on the I guess any notifiable specific change should be done on the Anyway, I think it is still worth aligning the behavior between the methods. |
|
Yeah this way of setting the locale is weird and we don't need to test explicitly for that in my opinion. I would at least change the test to be something realistic. |
@rodrigopedra |
Thanks for the feedback! Agreed - locale was a bad example since |
Call via() on $original instead of $notification so locale changes made in via() are preserved when sending notifications synchronously.
- testItPreservesLocaleSetInViaMethod -> testItPreservesNotificationStateMutatedInViaMethod - DummyNotificationWithLocaleInVia -> DummyNotificationWithViaMutation - Remove locale mocking, test generic channelData mutation instead
210ee80 to
399aa7e
Compare
Summary
Fixes bug where locale set dynamically in
via()is lost when sending notifications viasendNow().Problem
Inconsistency between
queueNotification()andsendNow()Both methods clone notification to
$originalfor sending, but callvia()on different objects:queueNotification()✅ CorrectsendNow()❌ BugWhen
via()mutates state (e.g., sets$this->locale), those changes happen on$notificationbut$originalis sent — losing the mutations.Real-world use case
Setting notification locale dynamically based on notifiable:
Works for queued notifications, fails silently for synchronous ones.
Solution
Align
sendNow()withqueueNotification():Test Plan
testItPreservesLocaleSetInViaMethodto verify locale set invia()is preserved