<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class RoleController extends Controller{

    public function add_role(Request $request){
        $re=DB::table('admin_role')->insert($request->all());
        if ($re){
            return $this->success([]);
        }
        return $this->error(300);
    }

    public function update_role(Request $request){
        $data['name']=$request->name;
        $data['routes']=$request->routes;
        $re=DB::table('admin_role')->where('id',$request->id)->update($data);
//        if ($re){
            return $this->success([]);
//        }
//        return $this->error(300);
    }

    public function del_role(Request $request){
        DB::table('admin_role')->where('id',$request->id)->delete();
        return $this->success([]);
    }

    public function all_role(){
        $role=DB::table('admin_role')->whereNotIn('name',['admin','root'])->get();
        if ($role){
            return $this->success_list($role,0,0);
        }
        return $this->error(300);
    }
}