From ccf67f5a77cc76cae2b4145c3d0b1dbe5715e377 Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Tue, 8 Oct 2024 19:32:45 +0100 Subject: [PATCH] fix: subtype features --- app/Http/Controllers/WorldController.php | 2 +- app/Models/Species/Species.php | 2 +- app/Models/Species/Subtype.php | 24 ++++++++++++------- .../views/world/_subtype_entry.blade.php | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/WorldController.php b/app/Http/Controllers/WorldController.php index c1a0ee12fd..1d2c081685 100644 --- a/app/Http/Controllers/WorldController.php +++ b/app/Http/Controllers/WorldController.php @@ -295,7 +295,7 @@ public function getSubtypeFeatures($id, Request $request) { } else { $features = $features ->filter(function ($feature) use ($subtype) { - return !($feature->subtype && $feature->subtype->id != $subtype->id); + return !($feature->subtypd_ids && !in_array($subtype->id, $feature->subtype_ids)); }) ->groupBy(['feature_category_id', 'id']); } diff --git a/app/Models/Species/Species.php b/app/Models/Species/Species.php index 5656e890eb..16ce8e9232 100644 --- a/app/Models/Species/Species.php +++ b/app/Models/Species/Species.php @@ -176,7 +176,7 @@ public function getSearchUrlAttribute() { * @return string */ public function getVisualTraitsUrlAttribute() { - return url('/world/species/'.$this->id.'/traits'); + return url('world/species/'.$this->id.'/traits'); } /** diff --git a/app/Models/Species/Subtype.php b/app/Models/Species/Subtype.php index 2c64599e6c..c7bb9551b3 100644 --- a/app/Models/Species/Subtype.php +++ b/app/Models/Species/Subtype.php @@ -67,13 +67,6 @@ public function species() { return $this->belongsTo(Species::class, 'species_id'); } - /** - * Get the features associated with this subtype. - */ - public function features() { - return $this->hasMany(Feature::class); - } - /********************************************************************************************** SCOPES @@ -184,7 +177,7 @@ public function getSearchUrlAttribute() { * @return string */ public function getVisualTraitsUrlAttribute() { - return url('/world/subtypes/'.$this->id.'/traits'); + return url('world/subtypes/'.$this->id.'/traits'); } /** @@ -204,4 +197,19 @@ public function getAdminUrlAttribute() { public function getAdminPowerAttribute() { return 'edit_data'; } + + /********************************************************************************************** + + OTHER FUNCTIONS + + **********************************************************************************************/ + + /** + * Get the features associated with this subtype. + */ + public function features() { + return Feature::all()->filter(function ($feature) { + return in_array($this->id, $feature->subtypes_ids ?? []); + }); + } } diff --git a/resources/views/world/_subtype_entry.blade.php b/resources/views/world/_subtype_entry.blade.php index 7e7b8ee8e4..ae15dceb56 100644 --- a/resources/views/world/_subtype_entry.blade.php +++ b/resources/views/world/_subtype_entry.blade.php @@ -17,7 +17,7 @@ - @if (count($subtype->features) && config('lorekeeper.extensions.visual_trait_index.enable_subtype_index')) + @if (count($subtype->features()) && config('lorekeeper.extensions.visual_trait_index.enable_subtype_index')) Visual Trait Index