本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::getOriginal方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getOriginal方法的具体用法?PHP Model::getOriginal怎么用?PHP Model::getOriginal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::getOriginal方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateCache
/**
* Update the cache for all operations.
*
* @param Model $model
*/
public function updateCache(Model $model)
{
$this->model = $model;
$this->applyToCountCache(function ($config) {
$foreignKey = $this->key($this->model, $config['foreignKey']);
if ($this->model->getOriginal($foreignKey) && $this->model->{$foreignKey} != $this->model->getOriginal($foreignKey)) {
$this->update($config, '-', $this->model->getOriginal($foreignKey));
$this->update($config, '+', $this->model->{$foreignKey});
}
});
}
示例2: updated
/**
* On update, delete previous file if changed
*
* @param Model $model eloquent
* @return mixed false or void
*/
public function updated(Model $model)
{
if (!($attachments = $model->attachments)) {
return;
}
foreach ($attachments as $fieldname) {
// Nothing to do if file did not change
if ($model->getOriginal($fieldname) == $model->{$fieldname}) {
return;
}
Croppa::delete('/uploads/' . $model->getTable() . '/' . $model->getOriginal($fieldname));
}
}
示例3: updating
/**
* Observe model saving for User.
*
* @param \Illuminate\Database\Eloquent\Model $model
*
* @return void
*/
public function updating(Model $model)
{
$changes = [];
$watchlist = (array) Arr::get($this->config, 'watchlist', []);
foreach ($watchlist as $attribute) {
if ($model->isDirty($attribute)) {
$changes[$attribute] = $model->getAttribute($attribute);
}
}
$recipient = new GenericRecipient($model->getOriginal('email'), $model->getRecipientName());
$this->factory->notify($recipient, $model, $changes, $this->config);
}
示例4: updated
/**
* On update, delete previous file if changed
*
* @param Model $model eloquent
* @return mixed false or void
*/
public function updated(Model $model)
{
if (!($attachments = $model->attachments)) {
return;
}
foreach ($attachments as $fieldname) {
// Nothing to do if file did not change
if (!$model->isDirty($fieldname)) {
continue;
}
$file = '/uploads/' . $model->getTable() . '/' . $model->getOriginal($fieldname);
$this->delete($file);
}
}
示例5: saving
/**
* On save, upload files.
*
* @param Model $model eloquent
*
* @return mixed false or void
*/
public function saving(Model $model)
{
if (!($attachments = $model->attachments)) {
return;
}
foreach ($attachments as $fieldname) {
if (Request::hasFile($fieldname)) {
// delete prev image
$file = FileUpload::handle(Request::file($fieldname), 'uploads/' . $model->getTable());
$model->{$fieldname} = $file['filename'];
if ($model->getTable() == 'files') {
$model->fill($file);
}
} else {
if ($model->{$fieldname} == 'delete') {
$model->{$fieldname} = null;
} else {
$model->{$fieldname} = $model->getOriginal($fieldname);
}
}
}
}
示例6: updating
public function updating(\Illuminate\Database\Eloquent\Model $model)
{
// An node is being updated.
// Rebuild the tree if the parent was changed.
// Get column names.
// Missing required columns will throw an exception.
$pkColumn = $model->getKeyName();
$leftColumn = $model->getLeftColumn();
$rightColumn = $model->getRightColumn();
$parentColumn = $model->getParentColumn();
$depthColumn = $model->getDepthColumn();
$groupColumn = $model->getGroupColumn();
$originalParentId = $model->getOriginal($parentColumn);
if ($originalParentId !== $model->{$parentColumn}) {
$model->syncOriginalAttribute($parentColumn);
echo 'parent changed from "' . $originalParentId . '" to "' . $model->{$parentColumn} . '"';
if (!is_null($originalParentId)) {
// Load original parent
$originalParent = $model::findOrFail($originalParentId, array_filter([$pkColumn, $leftColumn, $rightColumn, $depthColumn, $groupColumn]));
}
if (!is_null($model->{$parentColumn})) {
// Load new parent
$newParent = $model::findOrFail($model->{$parentColumn}, array_filter([$pkColumn, $leftColumn, $rightColumn, $depthColumn, $groupColumn]));
if ($newParent->{$leftColumn} > $model->{$leftColumn} and $newParent->{$leftColumn} < $model->{$rightColumn}) {
// This change would create a circular tree.
throw new \Exception('Changing this node\'s parent to ' . $model->{$parentColumn} . ' creates a circular reference');
}
}
//$originalParent = $model->where
// @TODO: Move this to the Trait. Override save().
dd($modelId);
/*
SELECT id FROM node
WHERE node.left BETWEEN 1 AND 10
AND node.id = 8
*/
// Rebuild the entire tree.
// @TODO: Be smarter about this method.
dd($model);
$rootNode = $model::where($parentColumn, '=', null)->first();
$rootNode->buildTree();
}
return true;
}
示例7: processRecursiveRollbackOperation
/**
* Processes a recursive rollback operation.
*
* @param mixed $movement
*
* @return array
*/
protected function processRecursiveRollbackOperation(Model $movement)
{
/*
* Retrieve movements that were created after
* the specified movement, and order them descending
*/
$movements = $this->movements()->where('created_at', '>=', $movement->getOriginal('created_at'))->orderBy('created_at', 'DESC')->get();
$rollbacks = [];
if ($movements->count() > 0) {
foreach ($movements as $movement) {
$rollbacks = $this->processRollbackOperation($movement);
}
}
return $rollbacks;
}
示例8: noUpload
/**
* Handle the case where no file has been uploaded for a field, but the field may have been cleared.
*
* @param Model $model
* @param string $fieldName
*/
private function noUpload(Model $model, $fieldName)
{
$prevFilePath = $model->getOriginal($fieldName);
if (!exists($model->{$fieldName}) && exists($prevFilePath)) {
$this->deleteFile($prevFilePath);
}
}
示例9: getDefaultValueFor
/**
* @param $attribute
* @return array|mixed
*/
public function getDefaultValueFor($attribute)
{
return $this->model->getOriginal($attribute);
}
示例10: getBefore
/**
* 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());
}
示例11: restored
public function restored(Eloquent $object)
{
$object->logs()->create(['type' => Model::RESTORE, 'data' => $object->getOriginal()]);
}
示例12: deleted
public function deleted(Model $model)
{
$oldNode = $model->getOriginal('node');
DB::table($model->getTable())->where(DB::raw("LOCATE('{$oldNode}', `node`)"), '>', 0)->delete();
}
示例13: update
/**
* Update the cache for all operations.
*/
public function update()
{
$this->apply(function ($config) {
$foreignKey = $this->key($config['foreignKey']);
if ($this->model->getOriginal($foreignKey) && $this->model->{$foreignKey} != $this->model->getOriginal($foreignKey)) {
$this->updateCacheRecord($config, '-', 1, $this->model->getOriginal($foreignKey));
$this->updateCacheRecord($config, '+', 1, $this->model->{$foreignKey});
}
});
}