admin管理员组

文章数量:1126094

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

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

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

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

On the front end there's just

<div v-if="$page.props.flash.message">{{$page.props.flash.message}}</div>

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.

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

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

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

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

On the front end there's just

<div v-if="$page.props.flash.message">{{$page.props.flash.message}}</div>

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.

Share Improve this question edited yesterday vStubbs asked Jan 9 at 0:03 vStubbsvStubbs 411 silver badge8 bronze badges 2
  • Flash messages only stays in the session for the next request. Once you see it and another request is made, it will be gone – Subha Commented Jan 9 at 5:17
  • What I'm confused about is what is causing the other request. No changes are being made on the page (at least not intentionally), and there are very few elements on it in the first place. – vStubbs Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 0

Have you tried:

session()->flash('success', 'Your action was successful!');

This is the correct way to persist flash message, according to this forum, and is the method I personally use when flashing messages.

本文标签: Laravel Inertiajsflash messages dissapearingStack Overflow