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:
- Uses
$fieldsor$resource->getFieldsForCreate(). - Creates a new model instance.
- Calls each field
mutate(). - Calls
creating()andsaving(). - Saves the model.
- Writes a created log entry.
- Calls each field
mutateLazy(). - Refreshes the model.
- Calls
created()andsaved(). - Dispatches
ResourceCreated.
Update
update(QoreResource $resource, Model $model, array $payload, array $fields = []): Model
Flow:
- Replicates the original model.
- Uses
$fieldsor$resource->getFieldsForEdit($model). - Calls each field
mutate(). - Calls
updating()andsaving(). - Saves the model.
- Calls each field
mutateLazy(). - Refreshes the model.
- Calls
updated()andsaved(). - Calls each field
logMutation(). - Dispatches
ResourceUpdated.
Delete
delete(QoreResource $resource, Model $model): void
Flow:
- Calls
deleting(). - Deletes the model.
- Calls
deleted(). - Writes a deleted log entry.
- Dispatches
ResourceDeleted.
Do not use the mutator for plain Eloquent writes that should intentionally skip Qore field logic.