<?php


namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

/**
 * Admin
 * @mixin Builder
 * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
 */
class Menu extends Authenticatable
{
    use HasApiTokens, Notifiable;
    protected $table = 'menus';
    protected $hidden = ['created_at', 'updated_at'];
    protected $fillable = ['parent_id', 'title', 'icon' ,'uri' ,'permission_name' ,'sort' ,'status' ,'type' ];

    const TYPE_MENU = 1;
    const TYPE_BUTTON = 2;

    const STATUS_SHOW = 1;
    const STATUS_HIDE = 2;

    protected function getCreatedAtAttribute($value)
    {
        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
    }

    protected function getUpdatedAtAttribute($value)
    {
        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
    }

    public function children()
    {
        return $this->hasMany(Menu::class, 'parent_id');
    }

    public function parent()
    {
        return $this->belongsTo(Menu::class, 'parent_id');
    }
}