use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\App;
class Technique extends Model
{
use HasFactory;
+ public static function locale2lang($locale) {
+ if (strtolower(substr($locale, 0, 2)) == 'de') return 'de';
+ return 'en';
+ }
+
public function chapters() {
return $this
->belongsToMany(Technique::class, 'technique_chapter', 'parent_id', 'child_id')
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 = [