Illuminate\Database\Eloquent\Model::performUpdate PHP Method

performUpdate() protected method

Perform a model update operation.
protected performUpdate ( Builder $query, array $options = [] ) : boolean
$query Builder
$options array
return boolean
    protected function performUpdate(Builder $query, array $options = [])
    {
        // If the updating event returns false, we will cancel the update operation so
        // developers can hook Validation systems into their models and cancel this
        // operation if the model does not pass validation. Otherwise, we update.
        if ($this->fireModelEvent('updating') === false) {
            return false;
        }
        // First we need to create a fresh query instance and touch the creation and
        // update timestamp on the model which are maintained by us for developer
        // convenience. Then we will just continue saving the model instances.
        if ($this->timestamps && Arr::get($options, 'touch', true)) {
            $this->updateTimestamps();
        }
        // Once we have run the update operation, we will fire the "updated" event for
        // this model instance. This will allow developers to hook into these after
        // models are updated, giving them a chance to do any special processing.
        $dirty = $this->getDirty();
        if (count($dirty) > 0) {
            $this->setKeysForSaveQuery($query)->update($dirty);
            $this->fireModelEvent('updated', false);
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * (non-PHPdoc)
  * @see \Illuminate\Database\Eloquent\Model::performUpdate()
  */
 public function performUpdate(Builder $query, array $options = [])
 {
     if (!Auth::user() instanceof User) {
         App::error(function (InvalidUserException $exception) {
             Log::error($exception);
             return 'Access denid for creating a new ' . get_called_class();
         });
     }
     $this->attributes[self::UPDATED_AT] = new \DateTime('now', new \DateTimeZone(env('APP_TIMEZONE', 'UTC')));
     $this->attributes[self::UPDATED_BY] = Auth::user()->id;
     return parent::performUpdate($query, $options);
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::performUpdate
Model