Filament custom Registration Form

Hey Y'all, I did a custom register component to add a plan selection, made the relationship between users and plans and this is how it looks my register class:
class Register extends BaseRegister
{
public Plan $plan;
protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
$this->getRoleFormComponent(),
])
->statePath('data'),
),
];
}

protected function getRoleFormComponent(): Component
{
return Select::make('Plan')
->relationship(name: 'plan', titleAttribute:'name')
->native(false)
->default('estandar')
->required();
}
}
class Register extends BaseRegister
{
public Plan $plan;
protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
$this->getRoleFormComponent(),
])
->statePath('data'),
),
];
}

protected function getRoleFormComponent(): Component
{
return Select::make('Plan')
->relationship(name: 'plan', titleAttribute:'name')
->native(false)
->default('estandar')
->required();
}
}
however, I'm getting an error Call to a member function isRelation() on null https://flareapp.io/share/x7XZpMAm
Flare
Call to a member function isRelation() on null - The error occurred at http://localhost/petlinkadmin/register
5 Replies
ingmontoya
ingmontoya6mo ago
up
awcodes
awcodes6mo ago
There is no record at this point so it can’t have a relationship.
ingmontoya
ingmontoya6mo ago
yeah, I've notice that. Thanks for your input!
awcodes
awcodes6mo ago
No need to be snippy. Just query the roles and use that for the options instead of querying the relationship.
ingmontoya
ingmontoya6mo ago
Oh no, sorry no snippy at all, just a not native english person. I did it in this way.
Select::make('plan_id')
->label('Plan')
->options(\App\Models\Plan::pluck('name', 'id'))
->native(false)
->default('2')
->required(),
Select::make('plan_id')
->label('Plan')
->options(\App\Models\Plan::pluck('name', 'id'))
->native(false)
->default('2')
->required(),