]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/Technique.php
serverside tech init
[alttp.git] / app / Models / Technique.php
index 1a54a0e1b29767f6f7ce29d1efc485ec1b17328d..0b25e47b19ded74f56c91a8c65a662c1021e2eae 100644 (file)
@@ -4,6 +4,7 @@ namespace App\Models;
 
 use Illuminate\Database\Eloquent\Factories\HasFactory;
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\App;
 
 class Technique extends Model
 {
@@ -17,7 +18,36 @@ class Technique extends Model
                        ->using(TechniqueChapter::class);
        }
 
+       public function relations() {
+               return $this
+                       ->belongsToMany(Technique::class, 'technique_relations', 'from_id', 'to_id')
+                       ->withPivot('type')
+                       ->using(TechniqueRelation::class);
+       }
+
+       public function translations() {
+               return $this->hasMany(TechniqueTranslation::class);
+       }
+
+       public function getTranslatedProperty($prop, $lang = null) {
+               if (is_null($lang)) $lang = App::getLocale();
+               foreach ($this->translations as $translation) {
+                       if ($translation->locale == $lang) {
+                               return $translation->{$prop};
+                       }
+               }
+               return $this->{$prop};
+       }
+
        protected $casts = [
                'index' => 'boolean',
+               'requirements' => 'array',
+               'rulesets' => 'array',
+               'title_icons' => 'array',
        ];
+
+       protected $with = [
+               'translations',
+       ];
+
 }