本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::getAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getAttributes方法的具体用法?PHP Model::getAttributes怎么用?PHP Model::getAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::getAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: performUpdate
/**
* 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;
}
示例2: castModel
/**
* 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;
}
示例3: newFromEloquentModel
/**
* 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;
}
示例4: assertModelPatched
/**
* 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);
}
示例5: newFromEloquentObject
/**
* 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;
}
示例6: validate
/**
* 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();
}
}
示例7: save
/**
* 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();
}
示例8: diff
/**
* @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;
}
示例9: update
/**
* 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;
});
}
示例10: associate
/**
* 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());
}
示例11: prepareDataAndRules
/**
* 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');
}
示例12: associateExisting
/**
* 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);
}
示例13: getIndexableAttributes
/**
* Return an array of attributes to be indexed.
*
* @param Model $model
* @return array
*/
public function getIndexableAttributes(Model $model)
{
return $model->getAttributes();
}
示例14: getAllAttributes
public function getAllAttributes()
{
return parent::getAttributes();
}
示例15: created
public function created(Eloquent $object)
{
$object->logs()->create(['type' => Model::CREATE, 'data' => $object->getAttributes()]);
}