fix: Laravel 13 session MessageBag 序列化兼容 (#24)#25
Open
PrintNow wants to merge 1 commit into
Open
Conversation
In Laravel 13, MessageBag objects stored via redirect()->with() are serialized to arrays, causing "Call to a member function get() on array" errors in blade templates. Introduce SessionMessage value object as a clean replacement, providing getTitle(), getMessage(), and getOptions() methods. Closes #24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Laravel 13 中,通过
redirect()->with()存储的MessageBag对象会被序列化为数组,导致 blade 模板调用->get()方法时报错:解决方案
引入
SessionMessage值对象替代MessageBag,提供语义清晰的getTitle()、getMessage()、getOptions()方法。修改文件
src/Support/SessionMessage.phpsrc/Support/helpers.phpadmin_info()、admin_toastr()改用SessionMessagesrc/Http/Controllers/ScaffoldController.phpbackWithSuccess()、backWithException()改用SessionMessageresources/views/partials/alerts.blade.phpArr::get()resources/views/partials/toastr.blade.phpArr::get()resources/views/partials/exception.blade.phpMessageBag::first()并缓存变量兼容性
兼容 Laravel 10、11、12、13。
Closes #24