Get districts through councils relationship

Posted 11 months ago by charlieBrown

I would like to use eager loading to retrieve the records of district through county_id.

jobs:
 county_id

counties: 
 id
 name
 district_id

district:
 id
 name

I have so far County

public function district(){
        return $this->belongsTo(District::class, 'district_id');
    }

District

public function counties(){
        return $this->hasMany(Council::class, 'district_id');
    }

How can I retrieve the district from jobs using relationships?

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