Flash messages ​
Flash messages are stable and boring mechanisms for sharing messages between requests.
In fact, The Boring Stack leverages flash messages for sending server-side validation error messages.
Sending flash messages ​
You can send a flash message in your action using req.flash()
.
js
module.exports = {
exits: {
success: {
responseType: 'redirect'
}
}
fn: async function () {
req.flash('message', 'Look like your timezone has changed')
req.flash('success', 'Billing details updated successfully')
req.flash('error', 'Your subscription could not be renewed')
return '/dashboard'
}
}
Reading flash messages ​
Flash messages sent in your actions are made available in a flash
page prop object with 3
properties like so.
success
: Use this for indicating successful operations.error
: Use this to communicate errors or failures.message
: Use this for generic messages.
js
import { usePage } from '@inertiajs/vue3'
const messages = usePage().props.flash.success // can be flash.message, flash.error
js
import { usePage } from '@inertiajs/react'
const messages = usePage().props.flash.success // can be flash.message, flash.error
js
import { page } from '@inertiajs/svelte'
const messages = page.props.flash.success // can be flash.message, flash.error
TIP
The properties of the flash prop are always an array