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

Unable to queue NotificationSent event listener for notifications with attachments #47372

Closed
antennaio opened this issue Jun 7, 2023 · 0 comments · Fixed by #47375
Closed
Labels

Comments

@antennaio
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants