getAttributes() public method

Get all of the current attributes on the model.
public getAttributes ( ) : array
return array
Example #1
0
 /**
  * Save an existing model and attach it to the parent model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return Model|bool
  */
 protected function performUpdate(Model $model)
 {
     $result = $this->query->update(array($this->localKey => $model->getAttributes()));
     if ($result) {
         $this->associate($model);
     }
     return $result ? $model : false;
 }
 /**
  * Get an array representing the properties of a model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return array
  */
 public static function castModel(Model $model)
 {
     $attributes = array_merge($model->getAttributes(), $model->getRelations());
     $visible = array_flip($model->getVisible() ?: array_diff(array_keys($attributes), $model->getHidden()));
     $results = [];
     foreach (array_intersect_key($attributes, $visible) as $key => $value) {
         $results[(isset($visible[$key]) ? Caster::PREFIX_VIRTUAL : Caster::PREFIX_PROTECTED) . $key] = $value;
     }
     return $results;
 }
 /**
  * Build new instance from an eloquent model object.
  *
  * @param \Illuminate\Database\Eloquent\Model $eloquentModel
  * @param array $name
  * @return \ProAI\Datamapper\Support\ValueObject
  */
 public static function newFromEloquentModel(EloquentModel $eloquentModel, $name)
 {
     $valueObject = new static();
     // get model data
     $dict = ['mapping' => $eloquentModel->getMapping(), 'attributes' => $eloquentModel->getAttributes()];
     foreach ($dict['mapping']['embeddeds'][$name]['attributes'] as $attribute => $column) {
         $valueObject->{$attribute} = $dict['attributes'][$column];
     }
     return $valueObject;
 }
 /**
  * Assert that a model has been patched.
  *
  * @param Model $model
  *      the model before it was patched.
  * @param array $changedAttributes
  *      the expected changed attributes - key to value pairs.
  * @param string|string[] $unchangedKeys
  *      the keys of the attributes that should not have changed.
  * @return $this
  */
 protected function assertModelPatched(Model $model, array $changedAttributes, $unchangedKeys = [])
 {
     /** We need to ensure values are cast to database values */
     $expected = $model->newInstance($changedAttributes)->getAttributes();
     $attributes = $model->getAttributes();
     foreach ((array) $unchangedKeys as $attr) {
         $expected[$attr] = isset($attributes[$attr]) ? $attributes[$attr] : null;
     }
     $expected[$model->getKeyName()] = $model->getKey();
     return $this->seeModelInDatabase($model, $expected);
 }
Example #5
0
 /**
  * Build new instance from an eloquent model object.
  *
  * @param \Illuminate\Database\Eloquent\Model $eloquentModel
  * @param array $name
  * @return \ProAI\Datamapper\Support\ValueObject
  */
 public static function newFromEloquentObject(EloquentModel $eloquentModel, $name)
 {
     $rc = new ReflectionClass(static::class);
     $valueObject = $rc->newInstanceWithoutConstructor();
     // get model data
     $dict = ['mapping' => $eloquentModel->getMapping(), 'attributes' => $eloquentModel->getAttributes()];
     foreach ($dict['mapping']['embeddeds'][$name]['attributes'] as $attribute => $column) {
         $valueObject->{$attribute} = $dict['attributes'][$column];
     }
     return $valueObject;
 }
 /**
  * Validate the given model.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  *
  * @throws \AltThree\Validator\ValidationException
  *
  * @return void
  */
 protected function validate(Model $model)
 {
     $attributes = $model->getAttributes();
     $messages = isset($model->validationMessages) ? $model->validationMessages : [];
     $validator = $this->factory->make($attributes, $model->rules, $messages);
     if ($validator->fails()) {
         throw new ValidationException($validator->getMessageBag());
     }
     if (method_exists($model, 'validate')) {
         $model->validate();
     }
 }
 /**
  * Save data to repository table
  *
  * @param Model $model
  * @param string $changeType
  */
 private function save(Model $model, $changeType)
 {
     $rc = new \ReflectionClass($model);
     $class = $rc->getShortName();
     $namespace = $rc->getNamespaceName();
     $repositoryClass = $namespace . '\\Repository' . $class;
     $repository = new $repositoryClass();
     $repository->{str_singular($model->getTable()) . '_id'} = $model->id;
     $repository->type = $changeType;
     $repository->data = $model->getAttributes();
     if (\Config::get('dbrepository.save_user') === true && \Auth::check()) {
         $repository->changed_by = \Auth::user()->id;
     }
     $repository->save();
 }
 /**
  * @param Model $left
  * @param Model $right
  * @param array $ignoredFields additional fields to ignore in the diff
  *
  * @return array
  * @throws IncompatibleModelMismatchException
  */
 public function diff(Model $left, Model $right, $ignoredFields = [])
 {
     if ($left instanceof $right === false) {
         throw new IncompatibleModelMismatchException();
     }
     $ignoredFields = array_merge($this->ignoredFields, $ignoredFields);
     $changes = [];
     $leftAttributes = array_except($left->getAttributes(), $ignoredFields);
     $rightAttributes = array_except($right->getAttributes(), $ignoredFields);
     $differences = array_diff($leftAttributes, $rightAttributes);
     foreach ($differences as $key => $value) {
         $changes[$key][0] = $leftAttributes[$key];
         $changes[$key][1] = $rightAttributes[$key];
         $changes[$key]['left'] = $leftAttributes[$key];
         $changes[$key]['right'] = $rightAttributes[$key];
     }
     return $changes;
 }
Example #9
0
 /**
  * POST: Update|Edit /{id}.
  */
 public function update()
 {
     return DB::transaction(function () {
         // Carregar ID
         $id = $this->getRouteId();
         // Carregar model
         $this->model = $this->model->find($id);
         // Criar serviço
         $service = $this->getService();
         // Validar
         $rules = $this->validatesUpdate;
         if (is_array($rules) && count($rules) > 0) {
             $data = array_merge([], $this->model->getAttributes(), $this->request->all());
             $params = ['table' => $this->model->getTable(), 'id' => $id];
             $service->validate($data, $rules, $params, $this->references);
         }
         // Executar
         $return = $service->update($this->model, $this->request, $this->references);
         return $return;
     });
 }
Example #10
0
 /**
  * Attach the model to its parent.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function associate(Model $model)
 {
     return $this->setEmbedded($model->getAttributes());
 }
Example #11
0
	/**
	 * Sets the proper data attributes and rules arrays depending on whether or not the model exists
	 *
	 * @param \Illuminate\Database\Eloquent\Model	$model
	 *
	 * @return array	//'data' and 'rules' indexes both arrays
	 */
	public function prepareDataAndRules($model)
	{
		//fetch the rules if any exist
		$rules = $this->getModelValidationRules();

		//if the model exists, this is an update
		if ($model->exists)
		{
			//only include dirty fields
			$data = $model->getDirty();

			//and validate the fields that are being updated
			$rules = array_intersect_key($rules, $data);
		}
		else
		{
			//otherwise validate everything
			$data = $model->getAttributes();
		}

		return compact('data', 'rules');
	}
Example #12
0
 /**
  * Associate an existing model instance to the given parent, without saving it to the database.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 protected function associateExisting($model)
 {
     // Get existing embedded documents.
     $records = $this->getEmbedded();
     $primaryKey = $this->related->getKeyName();
     $key = $model->getKey();
     // Replace the document in the parent model.
     foreach ($records as &$record) {
         if ($record[$primaryKey] == $key) {
             $record = $model->getAttributes();
             break;
         }
     }
     return $this->setEmbedded($records);
 }
 /**
  * Return an array of attributes to be indexed.
  *
  * @param Model $model
  * @return array
  */
 public function getIndexableAttributes(Model $model)
 {
     return $model->getAttributes();
 }
 public function getAllAttributes()
 {
     return parent::getAttributes();
 }
Example #15
0
 public function created(Eloquent $object)
 {
     $object->logs()->create(['type' => Model::CREATE, 'data' => $object->getAttributes()]);
 }
 /**
  * Get the pivot attribute from a model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  \Illuminate\Database\Eloquent\Relations\Relation  $parentRelation
  */
 public static function loadPivotAttribute(Model $model, Relation $parentRelation = null)
 {
     $attributes = $model->getAttributes();
     foreach ($attributes as $key => $value) {
         if ($key === 'pivot') {
             unset($model[$key]);
             $pivot = $parentRelation->newExistingPivot($value);
             $model->setRelation($key, $pivot);
         }
     }
 }
 /**
  * Get the model's "before" snapshot.
  *
  * @return array
  */
 protected function getBefore()
 {
     $lookupTable = ['created' => null, 'updated' => array_intersect_key($this->model->getOriginal(), $this->getAfter()), 'deleted' => $this->model->getAttributes(), 'soft-deleted' => ['deleted_at' => $this->model->{$this->model->getDeletedAtColumn()}], 'restored' => ['deleted_at' => $this->model->{$this->model->getDeletedAtColumn()}]];
     return collect($lookupTable)->get($this->getEvent());
 }
Example #18
0
 /**
  * Returns all the cache keys for an object.
  * 
  * @param  Model      $sourceObject
  * @param  array|null $modelAttributes
  * @return array
  */
 public static function cacheKeys(Model $sourceObject, array $modelAttributes = null)
 {
     $modelAttributes = !empty($modelAttributes) ? $modelAttributes : $sourceObject->getAttributes();
     $uniqueKeys = static::uniqueKeys($sourceObject);
     $prefix = static::getCacheKeyPrefix(get_class($sourceObject));
     $cacheKeys = [];
     foreach ($uniqueKeys as $key => $columns) {
         $columns = !is_array($columns) ? [$columns] : $columns;
         $keyedByColumn = [];
         foreach ($columns as $column) {
             // If the column doesn't exist in the model attributes, we don't return the cache key at all
             if (!array_key_exists($column, $modelAttributes)) {
                 continue 2;
             }
             $keyedByColumn[$column] = strval($modelAttributes[$column]);
         }
         ksort($keyedByColumn);
         $cacheKeys[$key] = $prefix . serialize($keyedByColumn);
     }
     return $cacheKeys;
 }
 /**
  * @param Model $object
  *
  * @return array
  */
 protected function getObjectData($object = null)
 {
     return $object->getAttributes();
 }
Example #20
0
 /**
  * get simple array from Model
  *
  * @param Model $model
  *
  * @return $result
  */
 public function getModelArray(Model $model)
 {
     $result = [];
     foreach ($model->getAttributes() as $key => $value) {
         $result[] = ['type' => 'text', 'name' => $key, 'key' => $key . ' :', 'value' => $value];
     }
     unset($result[0]);
     return $result;
 }
Example #21
0
 public function removeInvalidAttributes(Model $obj)
 {
     // $attributes = $this->getAllColumnsNames($obj);
     $attributes = Schema::getColumnListing($obj->getTable());
     $unwanted = array_diff(array_keys($obj->getAttributes()), $attributes);
     // dd($attributes);
     foreach ($unwanted as $key => $value) {
         unset($obj->{$value});
     }
     return $obj;
 }
Example #22
0
 /**
  * Get the pivot attributes from a model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return array
  */
 protected function cleanPivotAttributes(Model $model)
 {
     $values = array();
     foreach ($model->getAttributes() as $key => $value) {
         // To get the pivots attributes we will just take any of the attributes which
         // begin with "pivot_" and add those to this arrays, as well as unsetting
         // them from the parent's models since they exist in a different table.
         if (strpos($key, 'pivot_') === 0) {
             $values[substr($key, 6)] = $value;
             unset($model->{$key});
         }
     }
     return $values;
 }
 /**
  * @param Model $repository
  *
  * @return mixed
  */
 public function updating(Model $repository)
 {
     $this->setValidationRules($this->onUpdateRules);
     return $this->validate($repository->getAttributes());
 }