Skip to content

Installation ​

Install the Composer Package ​

Install Inertia Notifications with Composer:

bash
composer require inertiaui/notifications

Run the Install Command ​

Next, run the inertia-notifications:install command:

bash
php artisan inertia-notifications:install

The command publishes the configuration file and the migrations, skipping files you already published. It then lists the frontend steps below and the steps that set up the notification center.

Install the Frontend Package ​

Next, install the Vue or React package from your application's vendor directory:

bash
npm install vendor/inertiaui/notifications/vue
bash
npm install vendor/inertiaui/notifications/react

pnpm users

The package depends on @inertiaui/vanilla and tailwind-merge. pnpm installs the dependencies of a local directory only with the file: protocol, such as pnpm add file:vendor/inertiaui/notifications/vue. The install command prints this command once it finds a pnpm-lock.yaml file.

Installing From npm ​

You may also install the frontend package from npm. Use the same version as the Composer package:

bash
npm install @inertiaui/notifications-vue
bash
npm install @inertiaui/notifications-react

Tailwind CSS ​

Import the package's theme after Tailwind in your resources/css/app.css file, then add the package's source files to Tailwind's sources. The components need the theme for their colors and the stack layout of the toasts:

css
@import 'tailwindcss';
@import '@inertiaui/notifications-vue/theme.css';

@source '../../vendor/inertiaui/notifications/vue/src/**/*.{ts,vue}';
css
@import 'tailwindcss';
@import '@inertiaui/notifications-react/theme.css';

@source '../../vendor/inertiaui/notifications/react/src/**/*.{ts,tsx}';

To use the frontend package from npm, point the @source at its dist directory instead:

css
@source '../../node_modules/@inertiaui/notifications-vue/dist';
css
@source '../../node_modules/@inertiaui/notifications-react/dist';

See Styling to change the colors, spacing, and markup. In an application built on a Laravel starter kit, you may also import shadcn.css to use the kit's colors, as described in Laravel Starter Kits.

Start Listening for Toasts ​

Call initNotifications() in your frontend entry point, before createInertiaApp(). It listens for toasts in every Inertia response, so a toast flashed on a page without a Toaster still shows on the next page that has one:

js
import { createInertiaApp } from '@inertiajs/vue3'
import { initNotifications } from '@inertiaui/notifications-vue'

initNotifications()

createInertiaApp({
    // ...
})
js
import { createInertiaApp } from '@inertiajs/react'
import { initNotifications } from '@inertiaui/notifications-react'

initNotifications()

createInertiaApp({
    // ...
})

You may pass options to initNotifications(), such as durations, the limit, and error toasts, as Configuring Toasts describes.

Render the Toaster ​

Render one Toaster inside the Inertia app. Put it in a persistent layout, so it stays mounted while the user navigates:

vue
<script setup>
import { Toaster } from '@inertiaui/notifications-vue'
</script>

<template>
    <slot />
    <Toaster />
</template>
jsx
import { Toaster } from '@inertiaui/notifications-react'

export default function Layout({ children }) {
    return (
        <>
            {children}
            <Toaster />
        </>
    )
}

Your application is now ready to flash toasts from Laravel.

Server-Side Rendering ​

The components support server-side rendering, such as the build:ssr script of the Laravel starter kits. Your SSR entry point needs no changes, since initNotifications() and toast() do nothing on the server.

Each component renders the following on the server, and the rest waits for the browser:

  • The NotificationCenter renders its bell and its closed panel. The badge shows once the browser reads the counts from the shared prop.
  • The NotificationList renders the page's notifications. Their relative times, such as "5 minutes ago", may differ in the browser, and neither Vue nor React warns about that mismatch.
  • The Toaster renders nothing. Toasts show once the page hydrates, including the ones Laravel flashed for the page.
  • The NotificationPreferences component loads the user's preferences in the browser.