AthroHiro
AthroHiro
FFilament
Created by AthroHiro on 8/5/2024 in #❓┊help
$set Not working when using with a relationship
I have an Organisation Resource, an Organisation has one Location which is a mophOne relationship. With the code below I make it possible for the user to input just the postal_code and the number, I have an API which fetches the address based on those two fields. When the result get's back I fill the other fields with the $set() function as you can see. All of this works fine, the fields do get populated with the fetched data. But as soon as I press the save button on my resource, only the postal_code and the number get updated the other values reset to their original value before the $set happened ending up with an incorrect record in the database with the updated postal_code and number and the outdated street, city, province etc. Why isn't this working? How do I make this work?
Section::make('Adresgegevens')
->collapsible()
->columns(2)
->relationship('location')
->afterStateUpdated(function (?array $state, ?array $old, Set $set) {
if ($state['country_code'] !== 'NL') {
return;
}

if ($state['postal_code'] === $old['postal_code']
&& $state['number'] === $old['number']) {
return;
}

$locationData = LocationData::from([
'postal_code' => $state['postal_code'],
'number' => $state['number'],
'addition' => $state['addition'],
])->updateUsingAPI()->toArray();

$set('location.street', $locationData['street'] ?? null);
$set('location.city', $locationData['city'] ?? null);
$set('location.municipality', $locationData['municipality'] ?? null);
$set('location.province', $locationData['province'] ?? null);
$set('location.lat', $locationData['lat'].'' ?? null);
$set('location.long', $locationData['long'].'' ?? null);
})
->schema([
...
])
Section::make('Adresgegevens')
->collapsible()
->columns(2)
->relationship('location')
->afterStateUpdated(function (?array $state, ?array $old, Set $set) {
if ($state['country_code'] !== 'NL') {
return;
}

if ($state['postal_code'] === $old['postal_code']
&& $state['number'] === $old['number']) {
return;
}

$locationData = LocationData::from([
'postal_code' => $state['postal_code'],
'number' => $state['number'],
'addition' => $state['addition'],
])->updateUsingAPI()->toArray();

$set('location.street', $locationData['street'] ?? null);
$set('location.city', $locationData['city'] ?? null);
$set('location.municipality', $locationData['municipality'] ?? null);
$set('location.province', $locationData['province'] ?? null);
$set('location.lat', $locationData['lat'].'' ?? null);
$set('location.long', $locationData['long'].'' ?? null);
})
->schema([
...
])
10 replies
FFilament
Created by AthroHiro on 7/10/2024 in #❓┊help
delete index
The documentation says that we can delete any resource page we want (https://filamentphp.com/docs/3.x/panels/resources/getting-started#deleting-resource-pages), however when I delete the index page of my CompanyResource I get the following error:
Route [filament.companies-panel.resources.companies.index] not defined.
Route [filament.companies-panel.resources.companies.index] not defined.
I initially made a custom page but very soon I noticed some major disadvantages, f.e I downloaded the Apex Chart plugin and when initliazing a new chart the CLI asks for a resource, but when using a custom page you don't have one. So I decided to use a resource, the only page a logged in user is allowed to see is the edit page. So I wanted to disable the index and view pages. But than I run into the problem I mentioned before. What is the best way to achieve this scenario: a custom panel for companies, a company can login and edit just their own company fields and also see and edit their employees which do have a table but must also be addable/edditable in the edit company view using a relationmanager.
13 replies