'numeric', 'name' => 'required|alpha_space|min:3|max:255|unique:categories,name,{id}', 'category_type' => 'required', ); public function has_models() { return $this->hasMany('Model', 'category_id')->count(); } public function assetscount() { return $this->hasManyThrough('Asset', 'Model')->count(); } public function accessoriescount() { return $this->hasMany('Accessory')->count(); } public function accessories() { return $this->hasMany('Asset'); } public function assets() { return $this->hasManyThrough('Asset', 'Model'); } public function models() { return $this->hasMany('Model', 'category_id'); } }