public static function getActiveArray()
 {
     $permissions = AdminPermission::where('status', '=', '1')->orderBy('sort', 'asc')->get();
     foreach ($permissions as $value) {
         if ($value->pid != 0) {
             $perlists[$value->pid]['list'][] = ['id' => $value->id, 'name' => trans($value->name), 'desc' => trans($value->desc), 'status' => $value->status, 'menu' => $value->menu];
         } else {
             $perlists[$value->id]['name'] = trans($value->name);
         }
     }
     return $perlists;
 }
 public function run()
 {
     DB::table('admin_permissions')->delete();
     //系统管理菜单
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.sys_manage_desc', 'id' => 1, 'pid' => 0, 'sort' => 9, 'name' => 'admin.sys_manage', 'route' => 'fa fa-gear']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.user_manage_desc', 'id' => 2, 'pid' => 1, 'sort' => 1, 'name' => 'admin.user_manage', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getUserlist']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.user_add_desc', 'id' => 3, 'pid' => 1, 'sort' => 2, 'menu' => 0, 'name' => 'admin.user_add', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getUseradd|\\Pianke\\Http\\Controllers\\AdminManagerController@postUseradd']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.user_edit_desc', 'id' => 4, 'pid' => 1, 'sort' => 3, 'menu' => 0, 'name' => 'admin.user_edit', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getUseredit|\\Pianke\\Http\\Controllers\\AdminManagerController@postUseredit']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.user_change_status_desc', 'id' => 5, 'pid' => 1, 'sort' => 4, 'menu' => 0, 'name' => 'admin.user_change_status', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getUserstatus']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.role_manage_desc', 'id' => 6, 'pid' => 1, 'sort' => 5, 'name' => 'admin.role_manage', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getRolelist']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.role_add_desc', 'id' => 7, 'pid' => 1, 'sort' => 6, 'menu' => 0, 'name' => 'admin.role_add', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getRoleadd|\\Pianke\\Http\\Controllers\\AdminManagerController@postRoleadd']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.role_edit_desc', 'id' => 8, 'pid' => 1, 'sort' => 7, 'menu' => 0, 'name' => 'admin.role_edit', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getRoleedit|\\Pianke\\Http\\Controllers\\AdminManagerController@postRoleedit']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.role_delete_desc', 'id' => 9, 'pid' => 1, 'sort' => 8, 'menu' => 0, 'name' => 'admin.role_delete', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getRoledel']);
     \Pianke\Models\AdminPermission::create(['desc' => 'admin.permission_manage_desc', 'id' => 10, 'pid' => 1, 'sort' => 9, 'name' => 'admin.permission_manage', 'route' => '\\Pianke\\Http\\Controllers\\AdminManagerController@getPermission|\\Pianke\\Http\\Controllers\\AdminManagerController@getPeract|\\Pianke\\Http\\Controllers\\AdminManagerController@getPermenu']);
 }
Esempio n. 3
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     //检测是否登录,未登录跳转,登录了赋予菜单
     if (\Session::has('adminlogin')) {
         if (!env('PERMISSION_USE_CACHE', 'true')) {
             $uinfo = \Pianke\Models\AdminUser::find(\Session::get('adminlogin')->id);
             \Session::put('adminlogin', $uinfo);
             \Pianke\Models\AdminPermission::getCurPermissionArray(explode("|", $uinfo->role->permissions));
         }
         view()->share('menu', \Session::get('menu'));
     } else {
         return redirect()->action('\\Pianke\\Http\\Controllers\\AdminLoginController@getLogin');
     }
     //检测是否有权限访问操作
     if (!in_array('\\' . \Route::currentRouteAction(), \Session::get('curpermissions'))) {
         return redirect()->back()->withNotice(['type' => 'error', 'msg' => trans('admin.nopermission'), 'title' => trans('admin.permissionerror')]);
     }
     return $next($request);
 }
 public function getRoleedit()
 {
     $list = \Pianke\Models\AdminPermission::getActiveArray();
     $role = \Pianke\Models\AdminRole::find(\Request::input('id'));
     return view('admin.role_edit', ['role' => $role, 'plist' => $list]);
 }