<?php

namespace App;

use DB;
use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
/**
 * The database table used by the model.
 *
 * @var string
 */
    protected $table = 'role';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['slug', 'name', 'permission'];

    public function scopeActive($query)
    {
        return $query->whereStatus('1');
    }

    /**
     * Many-to-Many relations with User.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function users()
    {
        return $this->belongsToMany(User::class);
    }

    /*
     * Date: 15-08-2018
     * Author: Muhammad Arshad
     * Parameter:data= array of role module table values
     * Description:  this function will add the assigned user role
     */

            public static function Add($data)
    {

        $id = DB::table('role_user')->insertGetId($data);
        return $id;
    }

    /*
     * Date: 15-08-2018
     * Author: Muhammad Arshad
     * Parameter:user_id= user_id=1,12,3,4
     * Description:  this function will delete the assigned user role
     */

    public static function DeleteRole($user_id)
    {
        DB::table('role_user')->where('user_id', $user_id)->delete();
        return true;
    }

}
