public function isValid($isSaving = false)
 {
     $class = get_called_class();
     $rules = trait_config_get(get_called_class(), 'SilvertipSoftware\\LaravelTraitPack\\ValidatesTrait.rules', []);
     if (!$this->exists) {
         $creationRules = trait_config_get(get_called_class(), 'SilvertipSoftware\\LaravelTraitPack\\ValidatesTrait.creation_rules', []);
         $rules = array_merge($rules, $creationRules);
     }
     if ($this->fireModelEvent('validating') === false) {
         return false;
     }
     if (empty($rules)) {
         return true;
     }
     $attrs = $this->getAttributes();
     // loop through any mutated attributes and add those that have rules, and aren't there already
     $mutated = $this->getMutatedAttributes();
     foreach ($mutated as $key) {
         if (!array_key_exists($key, $attrs) && array_key_exists($key, $rules)) {
             $attrs[$key] = $this->mutateAttributeForArray($key, null);
         }
     }
     $validator = \Validator::make($attrs, $rules);
     $ret = $validator->passes();
     if (!$ret) {
         $this->errors = $validator->messages();
     }
     $this->fireModelEvent($isSaving ? 'validatedForSave' : 'validated', false);
     return $ret;
 }
 public static function bootUsesAlternateConnection()
 {
     $clz = get_class();
     $conn = trait_config_get($clz, 'SilvertipSoftware\\LaravelTraitPack\\UsesAlternateConnection.connection');
     if ($conn == null) {
         foreach (array_merge([$clz => $clz], class_parents($clz)) as $clz2) {
             $conn = \config('database.alternateConnections.' . $clz2);
             if ($conn != null) {
                 break;
             }
         }
     }
     trait_config_set($clz, 'SilvertipSoftware\\LaravelTraitPack\\UsesAlternateConnection.connection', $conn);
 }
 public function scopeActive($query)
 {
     $fieldName = trait_config_get(get_class(), 'SilvertipSoftware\\LaravelTraitPack\\HasActiveState.field', 'active');
     return $query->where($fieldName, 1);
 }