Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

philipbaginski's avatar

Laravel Nova relations problem

Hi! I'm Laravel Nova newbie and got a problem I can not idea how to solve:

I have resource eg. Humans. During creating new Human I have to add father, mother and grandfather. All data are stored in the same table - humans. Human belongs to: father, mother, grandfather. Grandfathers, mothers and fathers have many humans.

In resourse file I have:

BelongsTo::make('Human', 'mother'), BelongsTo::make('Human', 'father'), BelongsTo::make('Human', 'grandfather'),

, and in model file I have:

public function mother() { return $this->belongsTo(Human::class); }

public function father() { return $this->belongsTo(Human::class); }

public function grandfather() { return $this->belongsTo(Human::class); }

It works, but I don't know how to make own names in resource file for mother, father and grandfather and also I don't know how to make relation HasMany in model to show humans belongs to eg. mother

Thank you for any advice.

0 likes
2 replies
devfrey's avatar
devfrey
Best Answer
Level 11

Nova guesses the name of the resource based on the first parameter passed to BelongsTo::make(). You should be explicit about the associated resource if you want to alter the labels:

BelongsTo::make('Mother', 'mother', Human::class), // note: Human = resource class
BelongsTo::make('Father', 'father', Human::class),
BelongsTo::make('Grandfather', 'grandfather', Human::class),
1 like
philipbaginski's avatar

Thank you. It works. There is only one problem: On Index page and Detail page I can see: Father, Mother, Grandfather labels. But on Edit page I see Horse label next to select field.

One question more: how to list humans belonging to eg. grandfather?

In model file I did:

public function humans() { return $this->hasMany(Human::class); }

, and in resource file I have:

HasMany::make('humans', Human::class),

, but it does not work.

Please or to participate in this conversation.