<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{

    protected $table = 'roles';
    
    protected $fillable = [
        'name','display_name','description','flag','multiple_type'
    ];
    
    public $timestamps = true;

    public function rolepermission()
    {
        return $this->hasMany('App\RolePermission');
    }

    public function userRole()
    {
        return $this->hasMany('App\UserRole');
    }

       /**
     * get permissions related to role.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function permissions()
    {
        return $this->belongsToMany(
            'App\Permission', 'role_permission', 'role_id' , 'permission_id'
        );
    }

     public function permission()
    {
        return $this->permissions->first();
    }
}
