在 Laravel Livewire 中将数据长期保存到会话中?
我有一个社交网络,希望在会话中存储用户兴趣喜欢/不喜欢,因为有很多子页面我需要这些数据,并且我想避免在每个页面上查询数据库。但是,您似乎只能在 Livewire 中的会话中保存闪存数据。
通常的 Laravel $request->session()->put(...)
功能在会话中长期保存数据似乎在 Livewire 中不起作用?那么我如何才能在会话中长期保存数据,或者还有其他选项或功能吗?
I have a social network and want to store user interests likes/dislikes in a session since there are many subpages where I need this data and I want to avoid querying the database for that on every page. However, it seems you can only save flash data in sessions in Livewire.
The usual Laravel $request->session()->put(...)
feature to save data long term in sessions doesn't seem to work in Livewire? So how could I save data long term in sessions or is there an other option or feature?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以,我自己找到了答案。
实际上,您可以只使用
session()->put('key', 'value')
。我想知道为什么这没有正式记录。也许这对你们中的某些人也有帮助。
So, I just found out the answer by myself.
You can actually just use
session()->put('key', 'value')
.I wonder why this isn't officially documented tho. Maybe this helps someone of you too.
在 Livewire 组件中:
在视图刀片中:
In livewire component:
In view blade: