F
Filamentβ€’2mo ago
Patrick

FBlog won't save post when TiptipEditor output is set to JSON.

I'm trying out the blog plugin for filament. I already had Tiptap editor installed and changed the config to save output as JSON. This will result in an "array to string conversion" when trying to save the post. Added the body of the post to the $casts as array solves it, but since the Post model resides in the vendor folder I can't edit this. Is there a way to work around this?
3 Replies
Patrick
Patrickβ€’2mo ago
Is it possible to change the $casts array via a model event? Like when it's booted for example could cast the body to an array if a tiptap output in config is set to json, just have to find out how to do this πŸ˜„ I tried addin this to my AppServiceProvider:
if(config('filament-tiptap-editor.output') === TiptapOutput::Json){
Event::listen('eloquent.booting: Firefly\FilamentBlog\Models\Post', function (Post $post) {
$post->mergeCasts([
'body' => 'array'
]);
});
};
if(config('filament-tiptap-editor.output') === TiptapOutput::Json){
Event::listen('eloquent.booting: Firefly\FilamentBlog\Models\Post', function (Post $post) {
$post->mergeCasts([
'body' => 'array'
]);
});
};
It adds it to the casts array but does not resolve the issue
toeknee
toekneeβ€’2mo ago
You'll need to override the model withy our own one that extends the original. Or do a PR to the FBlog to allow setting your own Post Model Class like they have done for the user model class.
Patrick
Patrickβ€’2mo ago
yea i thought so, i do wonder why overriding the casts on runtime does not work thans for the reply!
Want results from more Discord servers?
Add your server