belongsToMany(Technique::class, 'technique_chapter', 'parent_id', 'child_id') ->withPivot('level', 'order') ->orderByPivot('order') ->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', ]; }