Send mail and a database notification

via() can return mail and database. The Vue bell reads the database row. It does not read the mailable.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-mail-and-database-notification.md
via() can return mail and database. The Vue bell reads the database row. It does not read the mailable.
Do not Mail::send and notify with two different texts that can drift.
Do not put the HTML of the mail into the database column and render it with v-html.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel notification mail and database” create a mailable and a notification and send both by hand. One notification can list both channels. The notifications guide is the bell. This page is via().

TL;DR

  • via() can return mail and database.
  • The Vue bell reads the database row.
  • It does not read the mailable.
  • Do not Mail::send and notify with two different texts that can drift.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

php
public function via(object $notifiable): array
{
    return ['mail', 'database'];
}

The database channel needs the notifications table:

shell
php artisan notifications:table
php artisan migrate

toArray() is what the bell stores. toMail() is the email. Keep the secrets out of both. The Vue page still loads the unread rows the way the notifications guide shows. You do not poll the mailbox.

What to avoid#

Gotcha

Do not Mail::send and notify with two different texts that can drift. Do not put the HTML of the mail into the database column and render it with v-html.

FAQ#

How do I send mail and a database notification?

via() can return mail and database. The Vue bell reads the database row. It does not read the mailable.

What goes wrong with Laravel notification mail and database?

Many developers create a mailable and a notification and send both by hand. Do not Mail::send and notify with two different texts that can drift.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.