<?php
namespace App\Models;

class Role extends BaseModel
{
    protected $table = 'roles';
    protected $fillable = ['name', 'display_name', 'description' ];
    protected $appends = ['menus_ids', 'menus_uris'];

    public function users()
    {
        return $this->belongsToMany(Admin::class, 'role_user', 'role_id', 'user_id');
    }

     public function menus()
    {
        return $this->belongsToMany(Menu::class, 'role_menu', 'role_id', 'menu_id');
    }

    public function getMenusIdsAttribute()
    {
        return $this->menus->pluck('id')->toArray();
    }

    public function getMenusUrisAttribute()
    {
        return $this->menus->pluck('uri')->toArray();
    }
}