F
Filamentβ€’3mo ago
LiruLiruLiru

Is it possible to use relationships inside my form when extending the Auth\Register class?

I'm trying to extend Filament\Pages\Auth\Register because i want to add more fields to my register form. I'm trying to use a Fieldset with ->relationship but I'm getting Call to a member function playerProfile() on null I've worked with Filament in the past and I've read the documentation, but I feel like either I'm missing something obvious or this is not possible out of the box? My code: /app/Filament/Pages/Auth/Register.php
Fieldset::make('player')
->relationship('playerProfile')
->schema([
Select::make('level')
->relationship(name: 'level', titleAttribute: 'name'),
Select::make('gender')
->options(['0' => 'M', '1' => 'F']),
])
Fieldset::make('player')
->relationship('playerProfile')
->schema([
Select::make('level')
->relationship(name: 'level', titleAttribute: 'name'),
Select::make('gender')
->options(['0' => 'M', '1' => 'F']),
])
/app/Models/User.php
public function playerProfile(): HasOne
{
return $this->hasOne(PlayerProfile::class);
}
public function playerProfile(): HasOne
{
return $this->hasOne(PlayerProfile::class);
}
/app/Models/PlayerProfile.php
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
Solution:
add ->model(User::class) in the form ```php protected function getForms(): array {...
Jump to solution
3 Replies
Solution
LeandroFerreira
LeandroFerreiraβ€’3mo ago
add ->model(User::class) in the form
protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->model(User::class)
->schema([...
protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->model(User::class)
->schema([...
LiruLiruLiru
LiruLiruLiruOPβ€’3mo ago
thanks a lot for this, this was it - I thought I tried this but I must have used wrong syntax or something, then I assumed it was linked to the User model by default - thanks again for your help!
LeandroFerreira
LeandroFerreiraβ€’3mo ago
NP.. nice nickname btw πŸ˜…
Want results from more Discord servers?
Add your server