calling method to get data

within the context of a form, what's the right way to get the data for this component? I get Using $this when not in object context when I try to call the getOwners() method I created.
Tab::make('Contacts')
->schema([
ContactCard::make('contacts')->items(function (Model $record) {
//I could just get the data here, but it seems messy to me.
return $this->getOwners();
}),
]),
Tab::make('Contacts')
->schema([
ContactCard::make('contacts')->items(function (Model $record) {
//I could just get the data here, but it seems messy to me.
return $this->getOwners();
}),
]),
3 Replies
Jon Mason
Jon MasonOP15mo ago
I got it working doing this:
ContactCard::make('contacts')->items(function (Model $record) {
$collection = $record->owners->map(function ($item) {
return ['name' => $item->first_name, 'title' => 'Owner'];
});

return $collection->toArray();
}),
ContactCard::make('contacts')->items(function (Model $record) {
$collection = $record->owners->map(function ($item) {
return ['name' => $item->first_name, 'title' => 'Owner'];
});

return $collection->toArray();
}),
This is only my proof of concept, and I think what I actually need to get in terms of data is going to be more complicated. I still don't know if it all needs to live in this closure, or if I should have a separate class somewhere? Would love anyones take on best practices.
ZedoX
ZedoX15mo ago
you can make a static method? static::getOwners($record)
Jon Mason
Jon MasonOP15mo ago
that worked, thx!
Want results from more Discord servers?
Add your server