Skip to main content

Mutator

The resource mutator performs Qore Resource CRUD outside the default Qore Resource controllers.

Use it when you need custom routes, actions, imports or jobs, but still want field mutation, resource hooks, logging and resource events to behave like normal resource forms.

Pass the same resource and payload shape that a normal Qore form would use. That keeps validation, lazy mutation and lifecycle hooks predictable.

$model = qore()->mutator()->store($resource, $payload);

$model = qore()->mutator()->update($resource, $model, $payload);

qore()->mutator()->delete($resource, $model);

Store

store(QoreResource $resource, array $payload, array $fields = []): Model

Flow:

  1. Uses $fields or $resource->getFieldsForCreate().
  2. Creates a new model instance.
  3. Calls each field mutate().
  4. Calls creating() and saving().
  5. Saves the model.
  6. Writes a created log entry.
  7. Calls each field mutateLazy().
  8. Refreshes the model.
  9. Calls created() and saved().
  10. Dispatches ResourceCreated.

Update

update(QoreResource $resource, Model $model, array $payload, array $fields = []): Model

Flow:

  1. Replicates the original model.
  2. Uses $fields or $resource->getFieldsForEdit($model).
  3. Calls each field mutate().
  4. Calls updating() and saving().
  5. Saves the model.
  6. Calls each field mutateLazy().
  7. Refreshes the model.
  8. Calls updated() and saved().
  9. Calls each field logMutation().
  10. Dispatches ResourceUpdated.

Delete

delete(QoreResource $resource, Model $model): void

Flow:

  1. Calls deleting().
  2. Deletes the model.
  3. Calls deleted().
  4. Writes a deleted log entry.
  5. Dispatches ResourceDeleted.

Do not use the mutator for plain Eloquent writes that should intentionally skip Qore field logic.