public function store($id)
 {
     $inputs = Input::all();
     $permission_id = Input::get('permission_id', null);
     $inputs['parent_id'] = $id;
     $inputs['type'] = 1;
     if (empty($permission_id)) {
         //创建
         $isset = Permission::where('name', $inputs['name'])->first();
         if (is_null($isset)) {
             Permission::create($inputs);
             $message = array('result' => true, 'content' => '添加操作权限成功,重新登陆后即可更新左侧菜单栏');
             return redirect('admin/permissions/' . $id . '/indexPermission')->with('message', $message);
         } else {
             $message = array('result' => false, 'content' => '添加操作权限失败,此权限名称已存在');
             return Redirect::back()->with('message', $message);
         }
     } else {
         //编辑
         $permission = Permission::find($permission_id);
         $isset = Permission::whereNotIn('id', array($permission_id))->where('name', $inputs['name'])->first();
         if (is_null($isset)) {
             $permission->update($inputs);
             $message = array('result' => true, 'content' => '编辑操作权限成功');
             return redirect('admin/permissions/' . $id . '/indexPermission')->with('message', $message);
         } else {
             $message = array('result' => false, 'content' => '编辑操作权限失败,此权限名称已存在');
             return Redirect::back()->with('message', $message);
         }
     }
 }
Exemplo n.º 2
0
 public function store()
 {
     $inputs = Input::all();
     $operation_permission = Input::get('operation_permission');
     $permission_id = Input::get('permission_id', null);
     if ($inputs['parent_id'] == 13) {
         $inputs['parent_id'] = 0;
     }
     $inputs['level'] = $inputs['parent_id'] == 0 ? 1 : 2;
     if (is_null($permission_id)) {
         array_except($inputs, array('operation_permission'));
         //创建
         $isset = Permission::where('name', $inputs['name'])->first();
         if (is_null($isset)) {
             $permission = Permission::create($inputs);
             if (isset($operation_permission) && $operation_permission == 'Y') {
                 $operation = array('create' => '新增', 'edit' => '编辑', 'delete' => '删除', 'show' => '详情', 'changeStatus' => '状态变更');
                 $permissions = [];
                 foreach ($operation as $operation_key => $operation_value) {
                     $permissions[] = array('name' => str_replace('.index', '', $permission->name) . '.' . $operation_key, 'display_name' => $operation_value, 'route' => $permission->route . '/' . $operation_key, 'type' => 1, 'parent_id' => $permission->id);
                 }
                 DB::table('permissions')->insert($permissions);
             }
             $message = array('result' => true, 'content' => '添加权限成功,重新登陆后即可更新左侧菜单栏');
             return redirect('admin/permissions')->with('message', $message);
         } else {
             $message = array('result' => false, 'content' => '添加权限失败,此权限名称已存在');
             return Redirect::back()->with('message', $message);
         }
     } else {
         //编辑
         $permission = Permission::find($permission_id);
         $isset = Permission::whereNotIn('id', array($permission_id))->where('name', $inputs['name'])->first();
         if (is_null($isset)) {
             $permission->update($inputs);
             $message = array('result' => true, 'content' => '编辑权限成功');
             return redirect('admin/permissions')->with('message', $message);
         } else {
             $message = array('result' => false, 'content' => '编辑权限失败,此权限名称已存在');
             return Redirect::back()->with('message', $message);
         }
     }
 }