Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $m = new ModelName;
- $m->name = 'Test model insert';
- $m->save();
- $m1 = ModelName::find( $m->id );
- if ($m1) {
- $m1->name = 'Test model update';
- $m1->save(); // Error occured here.
- }
- trait WithoutUpdateId
- {
- /**
- * Perform a model update operation.
- *
- * @param IlluminateDatabaseEloquentBuilder $query
- *
- * @return bool
- */
- protected function performUpdate(Builder $query)
- {
- // 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->usesTimestamps()) {
- $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) {
- unset($dirty['id']);
- $this->setKeysForSaveQuery($query)->update($dirty);
- $this->fireModelEvent('updated', false);
- $this->syncChanges();
- }
- return true;
- }
- class ModelName extends Model
- {
- use WithoutUpdateId;
- ...
- }
Add Comment
Please, Sign In to add comment