protected function registerSoftDelete(Mapper $mapper)
    {
        $entityMap = $mapper->getEntityMap();

        // Add Scopes
        $mapper->addGlobalScope(new SoftDeletingScope());

        // Register 'deleting' events
        $mapper->registerEvent('deleting', function ($event) use ($entityMap) {
            $entity = $event->entity;
            $wrappedEntity = $this->getMappable($entity);

            $deletedAtField = $entityMap->getQualifiedDeletedAtColumn();

            if (!is_null($wrappedEntity->getEntityAttribute($deletedAtField))) {
                return true;
            }

            $time = new Carbon();

            $wrappedEntity->setEntityAttribute($deletedAtField, $time);

            $plainObject = $wrappedEntity->getObject();
            $this->manager->mapper(get_class($plainObject))->store($plainObject);

            return false;
        });

        // Register RestoreCommand
        $mapper->addCustomCommand(Restore::class);
    }
protected function registerSoftDelete(Mapper $mapper)
    {
        $entityMap = $mapper->getEntityMap();

        // Add Scopes
        $mapper->addGlobalScope(new SoftDeletingScope());

        // Register 'deleting' events
        $mapper->registerEvent('deleting', function ($event) use ($entityMap) {
            $entity = $event->entity;
            $wrappedEntity = $this->getMappable($entity);

            $deletedAtField = $entityMap->getQualifiedDeletedAtColumn();

            if (!is_null($wrappedEntity->getEntityAttribute($deletedAtField))) {
                return true;
            }

            $time = new Carbon();

            $wrappedEntity->setEntityAttribute($deletedAtField, $time);

            $plainObject = $wrappedEntity->getObject();
            $this->manager->mapper(get_class($plainObject))->store($plainObject);

            return false;
        });

        // Register RestoreCommand
        $mapper->addCustomCommand(Restore::class);
    }
protected function registerSoftDelete ( Mapper $ mapper ) { $ entityMap = $ mapper -> getEntityMap ( ) ; // Add Scopes $ mapper -> addGlobalScope ( new SoftDeletingScope ( ) ) ; // Register 'deleting' events $ mapper -> registerEvent ( 'deleting' , function ( $ event ) use ( $ entityMap ) { $ entity = $ event -> entity ; $ wrappedEntity = $ this -> getMappable ( $ entity ) ; $ deletedAtField = $ entityMap -> getQualifiedDeletedAtColumn ( ) ; if ( ! is_null ( $ wrappedEntity -> getEntityAttribute ( $ deletedAtField ) ) ) { return true ; } $ time = new Carbon ( ) ; $ wrappedEntity -> setEntityAttribute ( $ deletedAtField , $ time ) ; $ plainObject = $ wrappedEntity -> getObject ( ) ; $ this -> manager -> mapper ( get_class ( $ plainObject ) ) -> store ( $ plainObject ) ; return false ; } ) ; // Register RestoreCommand $ mapper -> addCustomCommand ( Restore :: class ) ; }
By hooking to the mapper initialization event, we can extend it
with the softDelete capacity.

@param \Analogue\ORM\System\Mapper $mapper

@throws \Analogue\ORM\Exceptions\MappingException

@return bool|void
By hooking to the mapper initialization event we can extend it with the softDelete capacity .