Overview
TheCancelResourceRequestAction class handles the cancellation of pending resource requests. It logs the cancellation and permanently deletes the pending request from the database.
This action does not have any constructor dependencies. It can be instantiated directly without dependency injection.
Method Signature
Parameters
The pending resource request to cancel (Eloquent model instance)
The user cancelling the request (used for audit logging)
Return Value
This action returnsvoid (no return value).
Side Effects
This action performs the following side effects:- Audit Log: Creates a
ResourceLogentry with action typeCancelledbefore deletion - Database Delete: Permanently deletes the
PendingResourcerecord from the database
Example Usage
Cancel vs Deny
Understand the difference between cancelling and denying requests:Use Cases
Common scenarios for cancellation:- User cancels their own request before admin review
- Admin removes spam or invalid requests from the queue
- Duplicate requests that need to be cleaned up
- Outdated requests that are no longer needed
For declined legitimate requests, use
DenyResourceAction instead to preserve the full request history.Audit Trail
Even though the pending request is deleted, the cancellation is recorded in the audit log:- Action type:
Cancelled - Performer: The user who cancelled the request
- Resource details: Name, address, and other attributes from the pending request
- Timestamp: When the cancellation occurred
The audit log uses
PendingResource::toLogChanges() to capture all relevant request data before deletion, ensuring complete traceability.Error Scenarios
This action has minimal error scenarios:- Database errors: Will throw an exception if the log creation or deletion fails
- Already deleted: Will throw a model not found exception if the pending resource doesn’t exist
Source Reference
Implementation:/home/daytona/workspace/source/app/Actions/CancelResourceRequestAction.php:17