1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Models\Model;
- use Illuminate\Support\Facades\App;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class Menu.
- *
- * @package namespace App\Repositories\Models\Base;
- */
- class Menu extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'base_menus';
- protected $casts = ['meta' => 'array'];
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $guarded = [];
- // protected static function booted()
- // {
- // self::language();
- // }
- public function parent()
- {
- return $this->belongsTo(Menu::class, 'parent_id', 'id');
- }
- public function getParentNameAttribute()
- {
- return Menu::query()->where('id', $this->attributes['parent_id'])->value('name') ?? '--';
- }
- public function getMetaAttribute()
- {
- $meta = js2php($this->attributes['meta']);
- if (App::getLocale() == 'en') {
- $meta['title'] = $this->attributes['zh_title'];
- } else {
- $meta['title'] = $this->attributes['en_title'];
- }
- return $meta;
- }
- }
|