Matteo G
Matteo G
Explore posts from servers
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
foreach($fm as $key => $value) {
$fm[$key] = is_array($value) ? implode(',', $value) : $value;
}
foreach($fm as $key => $value) {
$fm[$key] = is_array($value) ? implode(',', $value) : $value;
}
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
the import worked! thanks! just generalized the code a bit to convert all arrays into a comma-separated string to ease the transition of all other models.
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
I didn't make it, it comes from the commonmark packages: League\CommonMark\Extension\FrontMatter\Data\SymfonyYamlFrontMatterParser League\CommonMark\Extension\FrontMatter\FrontMatterParser I'll see if I can find some readable source code
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
just tried it, getting:
ErrorException Array to string conversion
ErrorException Array to string conversion
on the changed line 😦
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
I was also thinking of that, but I don't know how hard it would be to change how Laravel handles converting to an array. This is the import script I'm using on the actual website.
$fmParser = new FrontMatterParser(new SymfonyYamlFrontMatterParser);
$files = Storage::files('markdown/projects');
foreach ($files as $file) {
$parsed = $fmParser->parse(Storage::get($file));
$project = Project::query()->updateOrCreate(['slug' => MarkdownUtils::getSlug($file)], [
'path' => $file,
'published_at' => $parsed->getFrontMatter()['date'],
'content' => $parsed->getContent(),
'fm' => $parsed->getFrontMatter(),
]);
$project->save();
}
$fmParser = new FrontMatterParser(new SymfonyYamlFrontMatterParser);
$files = Storage::files('markdown/projects');
foreach ($files as $file) {
$parsed = $fmParser->parse(Storage::get($file));
$project = Project::query()->updateOrCreate(['slug' => MarkdownUtils::getSlug($file)], [
'path' => $file,
'published_at' => $parsed->getFrontMatter()['date'],
'content' => $parsed->getContent(),
'fm' => $parsed->getFrontMatter(),
]);
$project->save();
}
getFrontMatter returns an array representing the frontmatter on a markdown file. It is stored in the database as a JSON column
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
hey, thank you so much! Works like a charm on the filament admin! but now it doesn't load properly on the rest of the website because it gets converted to a string (so looping over it does not work anymore :(). But I could change that section to explode the string it receives, though it seems a bit weird and inefficient (imploding to explode it right after...) ? They are stored as an array because of the way Eloquent does casts automatically, so i don't know how hard it would be to customize that process...
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
upping this since I'm still trying to make this work; I tried using mutateFormDataBeforeSave and handleRecordUpdate, but neither gets called before the error is thrown 😦
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
Forms\Components\KeyValue::make('fm'),
Forms\Components\KeyValue::make('fm'),
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
yes, but only on save I think (it displays fine). Is there a way to handle saving this field manually ? I thought maybe mutateFormDataBeforeSaving would work, but it does not even trigger, it seems
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
so could it be that it gets interpreted as an array when it gets sent back to be saved ? maybe because of the cast ?
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
an example of data is this:
{
"title": "example title"
"stack":["typescript","another tech"]
}
{
"title": "example title"
"stack":["typescript","another tech"]
}
Shows up fine, with the stack element separated by , but then the error happens when I try to save
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
done
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
the value can be an array (I know which ones are arrayis in advance)
35 replies
FFilament
Created by Matteo G on 8/21/2024 in #❓┊help
key-value and json arrays: {closure}(): Argument #1 ($value) must be of type ?string, array given
ah, and is there no way to convert it to and from an array on save ? I've been trying to use mutateFormDataBeforeSave, but it doesn't look to be triggering ?
35 replies
FFilament
Created by Matteo G on 8/10/2024 in #❓┊help
Getting owner record in custom association action
and same thing with dissociate action; it doesn't seem to work as intended but tries to call dissociate (I'd like it to use detach 😦 )
4 replies
FFilament
Created by Matteo G on 8/10/2024 in #❓┊help
Getting owner record in custom association action
got it, I just used $this->getOwnerRecord() and then attached the value with the extra values for the pivot table xD Is there another way that would allow me to avoid overriding this behaviour, though ? I have many relationships with this kind of requirements...
4 replies
FFilament
Created by Matteo G on 8/4/2024 in #❓┊help
Custom Pages and Widgets without resources
oh, thanks! I'll look into it 🙂
5 replies
FFilament
Created by Matteo G on 7/10/2024 in #❓┊help
Relation Manager and HasManyThrough: General error: 1 no such column on one of the models
but it doesn't solve the creation step redirection 😦
6 replies
FFilament
Created by Matteo G on 7/10/2024 in #❓┊help
Relation Manager and HasManyThrough: General error: 1 no such column on one of the models
got it! belongsToMany on both tables xD
6 replies