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

namespace App\Http\Controllers\Admin;use App\Http\Requests\PermissionCreateRequest;use App\Http\Requests\PermissionUpdateRequest;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use App\Models\Permission;class PermissionController extends Controller{public function index(Request $request){$keyword=$request->input('keyword','');$permissions=Permission::with('icon');if($keyword)goto P2gBodyx2;goto P2gNextx2;P2gBodyx2:$permissions->where('name','like',"%".$keyword."%")->orWhere('display_name','like',"%".$keyword."%");goto P2gx1;P2gNextx2:$permissions->where('parent_id',$request->input('parent_id',0));P2gx1:$permissions=$permissions->orderBy('sort','desc')->paginate($request->get('limit',10));return view('admin.permission.index',compact('permissions'));}public function create(){$permissions=$this->tree();return view('admin.permission.create',compact('permissions'));}public function store(PermissionCreateRequest $request){$data=$request->except('previous_url');$data['status']=1;if(Permission::create($data))goto P2gBodyx4;goto P2gNextx4;P2gBodyx4:return redirect()->to(route('admin.permission'))->with(['status'=>'添加成功']);goto P2gx3;P2gNextx4:P2gx3:return redirect()->to(route('admin.permission'))->withErrors('系统错误');}public function show($id){}public function edit($id){$permission=Permission::findOrFail($id);$permissions=$this->tree();return view('admin.permission.edit',compact('permission','permissions'));}public function update(PermissionUpdateRequest $request,$id){$permission=Permission::findOrFail($id);$data=$request->except('previous_url');if($permission->update($data))goto P2gBodyx6;goto P2gNextx6;P2gBodyx6:return redirect()->to($request->previous_url)->with(['status'=>'更新权限成功']);goto P2gx5;P2gNextx6:P2gx5:return redirect()->to(route('admin.permission'))->withErrors('系统错误');}public function destroy(Request $request){$id=$request->route('id');if(empty($id))goto P2gBodyx8;goto P2gNextx8;P2gBodyx8:return response()->json(['code'=>1,'msg'=>'请选择删除项']);goto P2gx7;P2gNextx8:P2gx7:$permission=Permission::find($id);$P2g0=!$permission;if($P2g0)goto P2gBodyxa;goto P2gNextxa;P2gBodyxa:return response()->json(['code'=>-1,'msg'=>'权限不存在']);goto P2gx9;P2gNextxa:P2gx9:if(Permission::where('parent_id',$id)->first())goto P2gBodyxc;goto P2gNextxc;P2gBodyxc:return response()->json(['code'=>2,'msg'=>'存在子权限禁止删除']);goto P2gxb;P2gNextxc:P2gxb:if($permission->delete())goto P2gBodyxe;goto P2gNextxe;P2gBodyxe:return response()->json(['code'=>0,'msg'=>'删除成功']);goto P2gxd;P2gNextxe:P2gxd:return response()->json(['code'=>1,'msg'=>'删除失败']);}public function sort(Request $request){$id=$request->input('id');$sort=$request->input('sort');if(Permission::where(['id'=>$id])->update(['sort'=>$sort]))goto P2gBodyxg;goto P2gNextxg;P2gBodyxg:return response()->json(['code'=>0,'msg'=>'ok']);goto P2gxf;P2gNextxg:return response()->json(['code'=>1,'msg'=>'排序值修改失败']);P2gxf:}}
?>