Esempio n. 1
0
 public function removeOrGrant(Request $request)
 {
     $data = $request->all();
     if ($data['TYPE'] == 1) {
         // remove
         UserRoleRight::where(['ROLE_ID' => $data['ROLE_ID'], 'RIGHT_ID' => $data['RIGHT_ID']])->delete();
     } else {
         UserRoleRight::insert(['ROLE_ID' => $data['ROLE_ID'], 'RIGHT_ID' => $data['RIGHT_ID']]);
     }
     $userRoleRight = UserRoleRight::getTableName();
     $userRight = UserRight::getTableName();
     $roleLeft = DB::table($userRoleRight . ' AS a')->join($userRight . ' AS b', 'a.RIGHT_ID', '=', 'b.ID')->where(['a.ROLE_ID' => $data['ROLE_ID']])->select(['b.ID', 'b.NAME'])->get();
     \DB::enableQueryLog();
     $roleRight = DB::table($userRight . ' AS a')->whereNotExists(function ($query) use($userRoleRight, $data) {
         $query->select(DB::raw('A.ID'))->from($userRoleRight . ' AS b')->whereRaw('b.RIGHT_ID = a.ID')->where(['b.ROLE_ID' => $data['ROLE_ID']]);
     })->get();
     \Log::info(\DB::getQueryLog());
     return response()->json(array('roleLeft' => $roleLeft, 'roleRight' => $roleRight));
 }
Esempio n. 2
0
File: User.php Progetto: hunglmtb/eb
 /**
  * One to Many relation
  *
  * @return Illuminate\Database\Eloquent\Relations\BelongsTo
  */
 public function role()
 {
     $user_user_role = UserUserRole::getTableName();
     $user_role_right = UserRoleRight::getTableName();
     $user_right = UserRight::getTableName();
     $rows = UserUserRole::join($user_role_right, "{$user_user_role}.ROLE_ID", '=', "{$user_role_right}.ROLE_ID")->join($user_right, "{$user_right}.ID", '=', "{$user_role_right}.RIGHT_ID")->where("{$user_user_role}.USER_ID", $this->ID)->select("{$user_right}.CODE")->distinct()->get();
     $rs = $rows ? $rows->map(function ($item, $key) {
         return $item->CODE;
     })->toArray() : [];
     return $rs;
 }