Nico
Nico
FFilament
Created by Nico on 2/27/2025 in #❓┊help
Set multiple properties on the same field
But don't the TextInput only have access to the single field? Which method on the extended TextInput class would I use to actually set multiple fields on the model during save? The properties are passed back fine I believe as a dd($state) in the dehydrateStateUsing returns all the properties currently. But the code to actually set it on the model just isn't being applied. It seems like the model returned from getModelInstance is not being used during create, only update. $company = $component->getModelInstance(); $company->address = $state['address'] ?? null; $company->city = $state['city'] ?? null; Sorry for the many questions. I've looked everywhere for an answer to this but can't really find anything specific. We're currently using Nova (migrating to Filament) where it's as simple as doing this in a Field class:
public function resolve($resource, $attribute = null): void
{
$this->withMeta([
'address' => $resource->address,
'zipcode' => $resource->zipcode,
'city' => $resource->city,
'country' => $resource->country,
'googleMapsApiKey' => config('services.google_maps.key'),
]);

parent::resolve($resource, $attribute);
}

protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{
if ($request->exists($requestAttribute)) {
$value = json_decode($request->input($requestAttribute));
if (!$value) {
return;
}

$model->{$attribute} = new Point($value->latitude, $value->longitude);
$model->address = $request->input('address');
$model->zipcode = $request->input('zipcode');
$model->city = $request->input('city');
$model->country = $request->input('country');
}
}
public function resolve($resource, $attribute = null): void
{
$this->withMeta([
'address' => $resource->address,
'zipcode' => $resource->zipcode,
'city' => $resource->city,
'country' => $resource->country,
'googleMapsApiKey' => config('services.google_maps.key'),
]);

parent::resolve($resource, $attribute);
}

protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{
if ($request->exists($requestAttribute)) {
$value = json_decode($request->input($requestAttribute));
if (!$value) {
return;
}

$model->{$attribute} = new Point($value->latitude, $value->longitude);
$model->address = $request->input('address');
$model->zipcode = $request->input('zipcode');
$model->city = $request->input('city');
$model->country = $request->input('country');
}
}
5 replies
FFilament
Created by Nico on 2/27/2025 in #❓┊help
Set multiple properties on the same field
Thanks for the response 👌 I've attempted that but it didn't really seem to make any difference. I'm also able to sent the data back fine (dd() in dehydrateStateUsing returns all the data) but it's just not being set on the model when saved during a create. How would I set multiple properties using a extended TextInput class?
5 replies