Installation
Install the Composer Package
Install Inertia Notifications with Composer:
composer require inertiaui/notificationsRun the Install Command
Next, run the inertia-notifications:install command:
php artisan inertia-notifications:installThe 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:
npm install vendor/inertiaui/notifications/vuenpm install vendor/inertiaui/notifications/reactpnpm 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:
npm install @inertiaui/notifications-vuenpm install @inertiaui/notifications-reactTailwind 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:
@import 'tailwindcss';
@import '@inertiaui/notifications-vue/theme.css';
@source '../../vendor/inertiaui/notifications/vue/src/**/*.{ts,vue}';@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:
@source '../../node_modules/@inertiaui/notifications-vue/dist';@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:
import { createInertiaApp } from '@inertiajs/vue3'
import { initNotifications } from '@inertiaui/notifications-vue'
initNotifications()
createInertiaApp({
// ...
})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:
<script setup>
import { Toaster } from '@inertiaui/notifications-vue'
</script>
<template>
<slot />
<Toaster />
</template>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
NotificationCenterrenders its bell and its closed panel. The badge shows once the browser reads the counts from the shared prop. - The
NotificationListrenders 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
Toasterrenders nothing. Toasts show once the page hydrates, including the ones Laravel flashed for the page. - The
NotificationPreferencescomponent loads the user's preferences in the browser.