Error with Builder Field

Hello, I did a fresh install of Laravel 10 with Filament 3, I created a resource page : - Title - string - Slug - string - Content - JSON I want to use the Builder component but I have 2 errors: The first is : Cannot use Filament\Forms\Components\Builder as Builder because the name is already in use So I changed the name to : use Filament\Forms\Components\Builder as PageBuilder this solves the first error, but when I try to add a block and save the resource, I get a second error: Array to string conversion It does save the title and slug, but for the content it replaces them with ?
INSERT INTO
`pages` (
`title`,
`slug`,
`content`,
`updated_at`,
`created_at`
)
VALUES
(dsf, dfs, ?, 2024 -02 -13 12: 28: 32, 2024 -02 -13 12: 28: 32)
INSERT INTO
`pages` (
`title`,
`slug`,
`content`,
`updated_at`,
`created_at`
)
VALUES
(dsf, dfs, ?, 2024 -02 -13 12: 28: 32, 2024 -02 -13 12: 28: 32)
Have you come across this problem before? Thanks !
Solution:
Check the model is casting the attribute to an array.
Jump to solution
4 Replies
jlove1672
jlove167210mo ago
What filament form field are you using for content? You can intercept the data before its saved by going into your CreatePages.php and adding this method protected function mutateFormDataBeforeCreate(array $data): array { dd($data) } This will help you see the format of content before its saved and allow you to modify it to suit your underlying db schema
Muxabble
MuxabbleOP10mo ago
The Filament Builder component must return a JSON object, and my database schema is also a JSON. the dd($data); returns an array, nothing abnormal, so I don't understand why Laravel is returning an error
array:3 [▼ // app/Filament/Resources/PageResource/Pages/CreatePage.php:15
"title" => "page title"
"slug" => "page-title"
"blocks" => array:1 [▼
0 => array:2 [▼
"type" => "heading"
"data" => array:2 [▼
"content" => "test"
"level" => "h4"
]
]
]
]
array:3 [▼ // app/Filament/Resources/PageResource/Pages/CreatePage.php:15
"title" => "page title"
"slug" => "page-title"
"blocks" => array:1 [▼
0 => array:2 [▼
"type" => "heading"
"data" => array:2 [▼
"content" => "test"
"level" => "h4"
]
]
]
]
Solution
RyMartin767
RyMartin76710mo ago
Check the model is casting the attribute to an array.
Muxabble
MuxabbleOP10mo ago
Oh! I thought it was automatic, thanks for the answer!
Want results from more Discord servers?
Add your server