Laravel error when sending email notification

  • 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')
                ['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

Categorised as laravel, notifications Tagged ,


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