Skip to content

Commit

Permalink
Update CustomFieldsForm.php
Browse files Browse the repository at this point in the history
Decoding json array stored in database.
  • Loading branch information
pntrivedy authored Jul 4, 2024
1 parent 4557664 commit bc40093
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Livewire/CustomFieldsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function mount(): void

$this->customFields = config('filament-edit-profile.custom_fields');

$this->form->fill($data['custom_fields'] ?? []);
$this->form->fill(json_decode($data['custom_fields'], true) ?? []);
}

public function form(Form $form): Form
Expand Down

1 comment on commit bc40093

@arisawali2014
Copy link

@arisawali2014 arisawali2014 commented on bc40093 Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we change the User model eloquent to json/array. i think we should not use json_decode anymore.
Because i ended up getting error:

json_decode(): Argument #1 ($json) must be of type string, array given

and then when i didn't use casts to the custom_fields it working

protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
-           'custom_fields' => 'array'
        ];
    }

but if we didn't use the casts it will error when inputing

$validated['custom_fields'] = [
            'phone' => $this->phone,
        ];

Array to string conversion

Please sign in to comment.