bernhard
bernhard
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
but only on edit, not on create. weird bug
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
even ->afterStateUpdated(fn ($state) => dd($state)) ->live(onBlur: true) throws the error, when the field loses the focus. So as you can see, it has nothing to do with the save / model
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
None is triggered before the error: KeyValue::make('data') ->mutateDehydratedStateUsing(fn ($state) => dd($state)) ->afterStateUpdated(fn ($state) => dd($state)) ->beforeStateDehydrated(fn ($state) => dd($state)) ->dehydrateStateUsing(fn ($state) => dd($state))
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
Method Filament\Forms\Components\KeyValue::getStateUsing does not exist.
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
Yeah. The idea is to fix this with some kind of "Using" method. But none of them are triggered early enought. I get the error before beforeStateDehydrated
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
But anyway, thanks for your help and time. Maybe I will sort it out otherwise
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
Not sure if modifing data just to make it work for a specific form isn't they way to go imho. Because on alll other places, the Dot is just fine. In the import Command, on the output, the API's where I have to use the data. So just the form is the problem, not the data, the storage or the formating
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
But once again, I dont think this is a problem on the model part of laravel, but on the filament part
Route::get("test", function() {
$test = \App\Models\Test::create([
"data" => [
"test.test" => "Test"
]
]);
$test->save();

$test->data = array_merge($test->data, [
"test2.test" => "test2",
]);
$test->save();
});
Route::get("test", function() {
$test = \App\Models\Test::create([
"data" => [
"test.test" => "Test"
]
]);
$test->save();

$test->data = array_merge($test->data, [
"test2.test" => "test2",
]);
$test->save();
});
Works. without any setDataAttribute
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
laravel/framework v11.31.0 The Laravel Framework.
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
this is the latest fork of the demo app
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
Thats now the whole model:
class Test extends Model
{
protected function casts()
{
return [
'data' => 'array',
];
}


public function setDataAttribute($value)
{
$transformedData = [];
foreach ($value as $key => $val) {
$newKey = str_replace('.', '_', $key);
$transformedData[$newKey] = $val;
}
return $transformedData;
}
}
class Test extends Model
{
protected function casts()
{
return [
'data' => 'array',
];
}


public function setDataAttribute($value)
{
$transformedData = [];
foreach ($value as $key => $val) {
$newKey = str_replace('.', '_', $key);
$transformedData[$newKey] = $val;
}
return $transformedData;
}
}
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
No description
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
Where should I add this? To the model?
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
Thats how its saved
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
No description
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
So when creating a new record, setting the value to test.test it works and is saved without problems. Then editing and adding something without a dot, it works as well. Then creating a new record without a dot, saving and adding the same test.test again, I get the error
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
This is without any extra code, just KeyValue::make('data')
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
Well thats funny.
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
This is again too late. The error isn't from the model, but from the field. But my first try on beforeStateDehydrated is wrong. I thought I get the string in beforeStateDehydrated, but I get already the wrong data:
{
"Test1" => "1"
"Test2" => "2"
"Test3" => "3"
"Test2_" => "3"
"Test" => array:1 [
"" => "444"
]
}
{
"Test1" => "1"
"Test2" => "2"
"Test3" => "3"
"Test2_" => "3"
"Test" => array:1 [
"" => "444"
]
}
49 replies
FFilament
Created by bernhard on 2/17/2025 in #❓┊help
Key-value Field with dot in key
Maybe we are speaking of different problems. The user enters the name like "O.B." into the KeyValue Field. So formatStateUsing or mutators are too late / too early. The error occurs on saving
49 replies