/** * Sets a data collection to a model attributes, relations will also be set. * @param array $saveData Data to save. * @param \October\Rain\Database\Model $model Model to save to * @return array The collection of models to save. */ protected function setModelAttributes($model, $saveData) { $this->modelsToSave[] = $model; if (!is_array($saveData)) { return; } $singularTypes = ['belongsTo', 'hasOne', 'morphOne']; foreach ($saveData as $attribute => $value) { $isNested = $attribute == 'pivot' || $model->hasRelation($attribute) && in_array($model->getRelationType($attribute), $singularTypes); if ($isNested && is_array($value)) { $this->setModelAttributes($model->{$attribute}, $value); } elseif ($value !== FormField::NO_SAVE_DATA) { $model->{$attribute} = $value; } } }
/** * Register the service provider. * @return void */ public function register() { parent::register(); Model::clearExtendedClasses(); $this->app->singleton('db.dongle', function ($app) { return new Dongle($this->getDefaultDatabaseDriver(), $app['db']); }); }
protected static function boot() { parent::boot(); self::saving(function ($channel) { if ($channel->code == null) { $channel->code = \Str::slug($channel->name); } }); if (strstr(\Url::current(), \Backend::baseUrl())) { self::backendBoot(); } }
/** * Create a new pivot model instance. * * @param \Illuminate\Database\Eloquent\Model $parent * @param array $attributes * @param string $table * @param bool $exists * @return void */ public function __construct(ModelBase $parent, $attributes, $table, $exists = false) { parent::__construct(); // The pivot model is a "dynamic" model since we will set the tables dynamically // for the instance. This allows it work for any intermediate tables for the // many to many relationship that are defined by this developer's classes. $this->setRawAttributes($attributes, true); $this->setTable($table); $this->setConnection($parent->getConnectionName()); // We store off the parent instance so we will access the timestamp column names // for the model, since the pivot model timestamps aren't easily configurable // from the developer's point of view. We can use the parents to get these. $this->parent = $parent; $this->exists = $exists; $this->timestamps = $this->hasTimestampAttributes(); }
/** * The models in October use a static property to store their events, these * will need to be targeted and reset ready for a new test cycle. * Pivot models are an exception since they are internally managed. * @return void */ protected function flushModelEventListeners() { foreach (get_declared_classes() as $class) { if ($class == 'October\\Rain\\Database\\Pivot') { continue; } $reflectClass = new ReflectionClass($class); if (!$reflectClass->isInstantiable() || !$reflectClass->isSubclassOf('October\\Rain\\Database\\Model') || $reflectClass->isSubclassOf('October\\Rain\\Database\\Pivot')) { continue; } $class::flushEventListeners(); } ActiveRecord::flushEventListeners(); }
/** * Get the attributes that should be converted to dates. * @return array */ public function getDates() { return array_merge(parent::getDates(), ['activated_at', 'last_login']); }
/** * Delete the group. * @return bool */ public function delete() { $this->users()->detach(); return parent::delete(); }
/** * Get the attributes that should be converted to dates. * @return array */ public function getDates() { return array_merge(parent::getDates(), ['last_attempt_at', 'suspended_at', 'banned_at']); }
/** * Convert the model instance to an array. * @return array */ public function toArray() { $result = parent::toArray(); if (isset($result['is_suspended'])) { $result['is_suspended'] = $this->getIsSuspendedAttribute($result['is_suspended']); } if (isset($result['is_banned'])) { $result['is_banned'] = $this->getIsBannedAttribute($result['is_banned']); } if (isset($result['last_attempt_at']) && $result['last_attempt_at'] instanceof DateTime) { $result['last_attempt_at'] = $result['last_attempt_at']->format('Y-m-d H:i:s'); } if (isset($result['suspended_at']) && $result['suspended_at'] instanceof DateTime) { $result['suspended_at'] = $result['suspended_at']->format('Y-m-d H:i:s'); } return $result; }
/** * The models in October use a static property to store their events, these * will need to be targeted and reset ready for a new test cycle. * Pivot models are an exception since they are internally managed. * @return void */ protected function flushModelEventListeners() { foreach (get_declared_classes() as $class) { if (!is_subclass_of($class, 'October\\Rain\\Database\\Model')) { continue; } if (is_subclass_of($class, 'October\\Rain\\Database\\Pivot')) { continue; } if ($class == 'October\\Rain\\Database\\Pivot') { continue; } $class::flushEventListeners(); } ActiveRecord::flushEventListeners(); }
/** * Receives the invalid model and sets the {@link model} and {@link errors} properties. * @param Model $model The troublesome model. */ public function __construct(Model $model) { $this->model = $model; $this->errors = $model->errors(); $this->evalErrors(); }
/** * Convert the model instance to an array. * @return array */ public function toArray() { $attributes = parent::toArray(); if (isset($attributes['permissions'])) { $attributes['permissions'] = $this->getPermissionsAttribute($attributes['permissions']); } return $attributes; }
/** * Convert the model instance to an array. * @return array */ public function toArray() { $result = parent::toArray(); if (isset($result['activated'])) { $result['activated'] = $this->getActivatedAttribute($result['activated']); } if (isset($result['permissions'])) { $result['permissions'] = $this->getPermissionsAttribute($result['permissions']); } if (isset($result['suspended_at'])) { $result['suspended_at'] = $result['suspended_at']->format('Y-m-d H:i:s'); } return $result; }
/** * Returns true if this logger should be used. * @return bool */ public static function useLogging() { return class_exists('Model') && Model::getConnectionResolver() && App::hasDatabase() && !defined('OCTOBER_NO_EVENT_LOGGING'); }
/** * Checks if a node (model) is expanded in the session. * @param Model $node * @return boolean */ public function isTreeNodeExpanded($node) { return $this->getSession('tree_node_status_' . $node->getKey(), $this->treeExpanded); }
/** * Convert the model instance to an array. * @return array */ public function toArray() { $result = parent::toArray(); if (isset($result['suspended'])) { $result['suspended'] = $this->getSuspended($result['suspended']); } if (isset($result['banned'])) { $result['banned'] = $this->getBanned($result['banned']); } if (isset($result['last_attempt_at']) and $result['last_attempt_at'] instanceof DateTime) { $result['last_attempt_at'] = $result['last_attempt_at']->format('Y-m-d H:i:s'); } if (isset($result['suspended_at']) and $result['suspended_at'] instanceof DateTime) { $result['suspended_at'] = $result['suspended_at']->format('Y-m-d H:i:s'); } return $result; }
/** * Clears event listeners of available plugin models and boots them */ protected final function rebootAllModels() { foreach (get_declared_classes() as $class) { /* * Reboot event listeners on all October\Rain\Database\Model subclasses * with exception of Pivot model that is a special, internal model for pivot tables * and should not be initialised outside of relation context. */ if (is_subclass_of($class, 'October\\Rain\\Database\\Model') && $class !== 'October\\Rain\\Database\\Pivot' && !is_subclass_of($class, 'October\\Rain\\Database\\Pivot')) { $class::flushEventListeners(); } } \October\Rain\Database\Model::flushEventListeners(); }