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
1 Answer
Reset to default 0Have 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
版权声明:本文标题:Laravel Inertia.js, flash messages dissapearing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736682031a1947469.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论