Eloquent Count nested relationships
问题 | Data | DataChildren | Category ---------------------------------- | id | id | id | name | data_id | name | | category_id | | | name | Data Model: public function data_children() { return $this->hasMany(DataChildren::class, 'data_id', 'id'); } DataChildren Model: public function category() { return $this->belongsTo(Category::class, 'category_id', 'id'); } I want to get count of Category based on Data id through DataChildren . I just want to take the Category records from Data so the result