✏️ Edit: Attribute.php
Path:
/home/thiqat5/tmphone.thiqatech.com/tm/app/Model/Attribute.php
Size: 772 B · Modified: 2021-11-17 23:00:14 · Perm: 0644 · Writable
← Back to directory
👁 View
⬇ Download
<?php namespace App\Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class Attribute extends Model { public function translations() { return $this->morphMany('App\Model\Translation', 'translationable'); } public function getNameAttribute($name) { if (auth('admin')->check() || auth('branch')->check()) { return $name; } return $this->translations[0]->value ?? $name; } protected static function booted() { static::addGlobalScope('translate', function (Builder $builder) { $builder->with(['translations' => function ($query) { return $query->where('locale', app()->getLocale()); }]); }); } }
💾 Save
Cancel
Save as UTF-8, newlines normalized to LF