Пример #1
0
 /**
  * get all role to show grid in admin
  * 
  * @return model
  */
 public static function getAllItemGrid()
 {
     $pager = General::getPagerOption();
     $model = self::orderBy($pager['order'], $pager['dir']);
     $model = $model->select('user.id as id', 'user.name as name', 'user.email as email', 'role.name as role_name')->leftJoin('role', 'role.id', '=', 'user.role_id');
     $filter = Input::get('filter');
     BaseModel::filterGrid($model);
     $model = $model->paginate($pager['limit']);
     return $model;
 }
Пример #2
0
 /**
  * override create function
  *  + save rule
  * @param array $attributes
  * @param array $rules
  */
 public static function create(array $attributes = array(), $rules = array(), $scope = array())
 {
     $result = null;
     DB::beginTransaction();
     try {
         $result = parent::create($attributes);
         if (count($rules)) {
             $dataInsert = [];
             if (in_array(RoleScope::RULE_ALL, $rules)) {
                 $rules = ['all'];
                 $scope = [RoleScope::SCOPE_COMPANY];
             }
             foreach ($rules as $key => $rule) {
                 $dataInsert[] = ['role_id' => $result->id, 'rule' => $rule, 'scope' => $scope[$key]];
             }
             RoleRule::insert($dataInsert);
         }
         DB::commit();
     } catch (Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
     return $result;
 }