<?php
/*
 本代码由 口号帮 创建
 创建时间 2019-05-08 16:22:09
 技术支持 口号帮 
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace App\Http\Controllers\Admin;use App\Http\Requests\RoleCreateRequest;use App\Http\Requests\RoleUpdateRequest;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use App\Models\Role;class RoleController extends Controller{public function index(){return view('admin.role.index');}public function create(){$P2g0=new Role();$role=$P2g0;return view('admin.role.create',compact('role'));}public function store(RoleCreateRequest $request){$data=$request->only(['name','display_name','type']);if(Role::create($data))goto P2gBodyx2;goto P2gNextx2;P2gBodyx2:return redirect()->to(route('admin.role'))->with(['status'=>'添加角色成功']);goto P2gx1;P2gNextx2:P2gx1:return redirect()->to(route('admin.role'))->withErrors('系统错误');}public function show($id){}public function edit($id){$role=Role::findOrFail($id);return view('admin.role.edit',compact('role'));}public function update(RoleUpdateRequest $request,$id){$role=Role::findOrFail($id);$data=$request->only(['name','display_name','type']);if($role->update($data))goto P2gBodyx4;goto P2gNextx4;P2gBodyx4:return redirect()->to(route('admin.role'))->with(['status'=>'更新角色成功']);goto P2gx3;P2gNextx4:P2gx3:return redirect()->to(route('admin.role'))->withErrors('系统错误');}public function destroy(Request $request){$ids=$request->get('ids');if(empty($ids))goto P2gBodyx6;goto P2gNextx6;P2gBodyx6:return response()->json(['code'=>1,'msg'=>'请选择删除项']);goto P2gx5;P2gNextx6:P2gx5:if(Role::destroy($ids))goto P2gBodyx8;goto P2gNextx8;P2gBodyx8:return response()->json(['code'=>0,'msg'=>'删除成功']);goto P2gx7;P2gNextx8:P2gx7:return response()->json(['code'=>1,'msg'=>'删除失败']);}public function permission(Request $request,$id){$role=Role::findOrFail($id);$permissions=$this->tree();foreach($permissions as $key1=>$item1){if($role->hasPermissionTo($item1['id']))goto P2gBodyxa;goto P2gNextxa;P2gBodyxa:$P2g0='checked';goto P2gx9;P2gNextxa:$P2g0=false;P2gx9:$permissions[$key1]['own']=$P2g0;if(isset($item1['_child']))goto P2gBodyxc;goto P2gNextxc;P2gBodyxc:foreach($item1['_child']as $key2=>$item2){if($role->hasPermissionTo($item2['id']))goto P2gBodyxe;goto P2gNextxe;P2gBodyxe:$P2g0='checked';goto P2gxd;P2gNextxe:$P2g0=false;P2gxd:$permissions[$key1]['_child'][$key2]['own']=$P2g0;if(isset($item2['_child']))goto P2gBodyxg;goto P2gNextxg;P2gBodyxg:foreach($item2['_child']as $key3=>$item3){if($role->hasPermissionTo($item3['id']))goto P2gBodyxi;goto P2gNextxi;P2gBodyxi:$P2g0='checked';goto P2gxh;P2gNextxi:$P2g0=false;P2gxh:$permissions[$key1]['_child'][$key2]['_child'][$key3]['own']=$P2g0;}goto P2gxf;P2gNextxg:P2gxf:}goto P2gxb;P2gNextxc:P2gxb:}return view('admin.role.permission',compact('role','permissions'));}public function assignPermission(Request $request,$id){$role=Role::findOrFail($id);$permissions=$request->get('permissions');if(empty($permissions))goto P2gBodyxk;goto P2gNextxk;P2gBodyxk:$role->permissions()->detach();return redirect()->to(route('admin.role'))->with(['status'=>'已更新角色权限']);goto P2gxj;P2gNextxk:P2gxj:$role->syncPermissions($permissions);return redirect()->to(route('admin.role'))->with(['status'=>'已更新角色权限']);}}
?>