Skip to content

Capturing of events and negating them #97

@Oskar-Mikael

Description

@Oskar-Mikael

We have a use case where we want to capture events when our models' fields and relations are being updated

This can be achieved with the events that are included in the eloquent model HasEvents trait, for example

        static::updating(function ($item) {
            if ($item->isApprovalRequired() && $item->requiresApprovalWhen($item->getDirty()) === true) {
                return self::captureSave($item);
            }
        });

This captures when the model is being updated, and if it requires us to approve it, captureSave will log the dirty fields and return false, thus negating whatever was to be updated

We've attempted to implement the same using the pivot events

        static::pivotAttaching(function ($item, $relationName, $pivotIds) {
            if ($item->isApprovalRequired() && $item->requiresApprovalWhen($item->getDirty()) === true) {
                return self::capturePivot($item, $relationName, $pivotIds, 'pivotAttaching');
            }
        });

However returning false in these events doesn't seem to negate the attaching or detaching. They are still performed.

Is it possible to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions