public function fill(array $attributes)
 {
     parent::fill($attributes);
     if (!$this->isNewModel() && is_array($this->behaviors)) {
         foreach ($this->behaviors as $class => &$configuration) {
             if (is_scalar($configuration)) {
                 $configuration = json_decode($configuration, true);
             }
         }
     }
 }
 public function validate()
 {
     $path = File::symbolizePath('$/' . $this->getFilePath());
     $this->validationMessages = ['className.uniq_model_name' => Lang::get('rainlab.builder::lang.model.error_class_name_exists', ['path' => $path])];
     Validator::extend('uniqModelName', function ($attribute, $value, $parameters) use($path) {
         $value = trim($value);
         if (!$this->isNewModel()) {
             // Editing models is not supported at the moment,
             // so no validation is required.
             return true;
         }
         return !File::isFile($path);
     });
     parent::validate();
 }
 public function validate()
 {
     $isNewModel = $this->isNewModel();
     $this->validationMessages = ['version.regex' => Lang::get('rainlab.builder::lang.migration.error_version_invalid'), 'version.unique_version' => Lang::get('rainlab.builder::lang.migration.error_version_exists'), 'scriptFileName.regex' => Lang::get('rainlab.builder::lang.migration.error_script_filename_invalid')];
     $versionInformation = $this->getPluginVersionInformation();
     Validator::extend('uniqueVersion', function ($attribute, $value, $parameters) use($versionInformation, $isNewModel) {
         if ($isNewModel || $this->version != $this->originalVersion) {
             return !array_key_exists($value, $versionInformation);
         }
         return true;
     });
     if (!$isNewModel && $this->version != $this->originalVersion && $this->isApplied()) {
         throw new ValidationException(['version' => Lang::get('rainlab.builder::lang.migration.error_cannot_change_version_number')]);
     }
     return parent::validate();
 }
 public function validate()
 {
     $pluginDbPrefix = $this->getPluginCodeObj()->toDatabasePrefix();
     if (!strlen($pluginDbPrefix)) {
         throw new SystemException('Error saving the table model - the plugin database prefix is not set for the object.');
     }
     $prefix = $pluginDbPrefix . '_';
     $this->validationMessages = ['name.table_prefix' => Lang::get('rainlab.builder::lang.database.error_table_name_invalid_prefix', ['prefix' => $prefix]), 'name.regex' => Lang::get('rainlab.builder::lang.database.error_table_name_invalid_characters'), 'name.unique_table_name' => Lang::get('rainlab.builder::lang.database.error_table_already_exists', ['name' => $this->name])];
     Validator::extend('tablePrefix', function ($attribute, $value, $parameters) use($prefix) {
         $value = trim($value);
         if (!Str::startsWith($value, $prefix)) {
             return false;
         }
         return true;
     });
     Validator::extend('uniqueTableName', function ($attribute, $value, $parameters) {
         $value = trim($value);
         $schema = $this->getSchema();
         if ($this->isNewModel()) {
             return !$schema->hasTable($value);
         }
         if ($value != $this->tableInfo->getName()) {
             return !$schema->hasTable($value);
         }
         return true;
     });
     $this->validateColumns();
     return parent::validate();
 }