Field with data from relationship (BelongsTo)

Hi ! I'm trying to display data from my user_profiles table on the User resource page but it doesn't work and I can't find why. Relationships are defined on both models and I used ->relatonship('profile') on my section.
// On the UserProfile.php model
public function user(): HasOne
{
return $this->hasOne(User::class);
}
// On the User.php model
public function profile(): BelongsTo
{
return $this->belongsTo(UserProfile::class);
}
// On my UsersResource.php resource
Forms\Components\Section::make('Profil')
->relationship('profile')
->schema([
Forms\Components\TextInput::make('country_code')
])
->columns(2),
// On the UserProfile.php model
public function user(): HasOne
{
return $this->hasOne(User::class);
}
// On the User.php model
public function profile(): BelongsTo
{
return $this->belongsTo(UserProfile::class);
}
// On my UsersResource.php resource
Forms\Components\Section::make('Profil')
->relationship('profile')
->schema([
Forms\Components\TextInput::make('country_code')
])
->columns(2),
Can someone help me ? Thanks!
2 Replies
LeandroFerreira
//user model
public function profile(): HasOne
{
return $this->hasOne(Profile::class);
}

//profile model
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

//user resource
Section::make('Profile')
->relationship('profile')
->schema([
//...
])
//user model
public function profile(): HasOne
{
return $this->hasOne(Profile::class);
}

//profile model
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

//user resource
Section::make('Profile')
->relationship('profile')
->schema([
//...
])
Benjamin
BenjaminOP2y ago
There was an error in one of my migrations 🤦‍♂️ It works finally, but maybe I should change relationships like that yes.
Want results from more Discord servers?
Add your server