Category: Laravel, api

Notifications in Laravel are typically used to notify users in your application. Users do not have to be the App\Models\User model, but can be any model that includes the Notifiable trait. However, sometimes there is no notifiable model involved, and you need to send a notification directly to a given email address, or a list of addresses. When you try to provide an email address to the send method of the Notification facade, like this: You will get the following error message: TypeError : get_class(): Argument #1 ($object) must be of type object, string given Luckily, the Laravel Framework has a solution for this, with on-demand notifications, that can be written like this: As you can see, the notification object MyNotification is used, but without a model that includes the Notifiable trait.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners