Closed
Description
Laravel Version
10.13.1
PHP Version
8.2.4
Database Driver & Version
MySQL 8 (Laravel Sail)
Description
Hello!
I believe I found a problem in Laravel 10.13.1 introduced by a recent change.
The issue is related to notifications with attachments (like PDF files). Due to the change, the NotificationSent
event listeners can't be queued anymore. An InvalidPayloadException
exception is thrown.
I included more information in the "Steps To Reproduce" section below.
Steps To Reproduce
Starting with a fresh installation of Laravel 10.13.1+:
1. Set up a notification with a file attachment (binary file such as PDF)
class ExampleNotification extends Notification
{
public function via(object $notifiable): array
{
return ['mail'];
}
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->line('Example notification with attachment.')
->attach(resource_path('files/sample.pdf'), [
'as' => 'sample.pdf',
'mime' => 'application/pdf',
]);
}
}
2. Set up a NotificationSent
event listener
class ExampleListener implements ShouldQueue
{
public function handle(NotificationSent $event): void
{
//
}
}
3. Listen to NotificationSent
event
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
NotificationSent::class => [
ExampleListener::class,
],
];
}
4. Notify a user
$user->notify(new \App\Notifications\ExampleNotification());
Result:
See Illuminate\Queue\InvalidPayloadException
with Unable to JSON encode payload. Error code: 5.
message.