zakaria_tbey
3 months ago
615
5
Nova

Laravel Nova BelongsTo field display nested relationship

Posted 3 months ago by zakaria_tbey

Hello Guys,

I've been struggling with this problem for the last 48 hours

I would like to add a BelongsTo field to display Universities Drop-down in a Student Resource

Here's my models : Student -> Section -> Course -> Departement -> University

class Student extends Model
{
    public function section()
    {
        return $this->belongsTo('App\Section');
    }
}

class Section extends Model
{
    public function courses()
    {
        return $this->belongsTo('App\Course');
    }
}

class Course extends Model
{
    public function departement()
    {
        return $this->belongsTo('App\Departement');
    }
}

class Departement extends Model
{
    public function university()
    {
        return $this->belongsTo('App\University');
    }
}

I was thinking about something like this :

class Student extends Model
{
    public function university()
    {
        return $this->section->courses->departement->university;
    }
}

But it doesn't really work

Any solution to properly solve this issue ?

staudenmeir/belongs-to-through package may works but not in my case because i have custom local keys and this package doesn't support custom local keys

Please sign in or create an account to participate in this conversation.