Laravel Inertia.js, flash messages disappearing
18:04 08 Jan 2025

I'm trying to implement flash messages upon a redirect. I added

        'flash' => [
            'message' => fn () => $request->session()->get('message')
        ],

to the HandleInertiaRequests.php file, and I have a simple Inertia link posting to a controller that redirects back as so

return \redirect()->back()->with('message', 'Item added successfully!');

In the frontend, there's just

{{$page.props.flash.message}}

The problem is that the message appears for half a second or so, and then disappears. It's as though the page gets refreshed as soon as it changes.

Any ideas what might be causing this?

EDIT: turned out that the issue was with the dependency declaration in my package.json.

I had

"@inertiajs/inertia": "^0.11.0",

whereas I got it working after npm install with:

"@inertiajs/vue3": "^2.0.0",

Near as I can tell, the core issue this produced was that the $page object itself was undefined as usePage() wouldn't work despite its import being present.

laravel flash inertiajs