Laravel error when sending email notification

Published
  • Laravel Version: 8.78.1
  • PHP Version: 8.0.10

I’ve created a custom command to run on a schedule and email a notification.

My Command class handle method:

public function handle()
{
    $sql = "SELECT * FROM Licences WHERE (Expired = 1)";
    $list = DB::select($sql);

    return (new NotifyExpiredLicences($list))->toMail('[email protected]');
}

My notification method:

public function toMail($notifiable)
{
    return (new MailMessage)
            ->subject('Clients with Expired Licences')
            ->markdown('vendor/notifications/expiredlicences', 
                ['clients' => $this->list, 'toname' => 'Me']);
}

Whenever I test this by running it manually with php artisan email:expired-licences I get the following error Object of class IlluminateNotificationsMessagesMailMessage could not be converted to int from my command class in the handle method.

However, the preview of my email works fine & displays as expected:

Route::get('/notification', function () {
    return (new SendExpiredLicences())->handle();
});

Source: Laravel

Published
Categorised as laravel, notifications Tagged ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq