Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more detail to manipulating changes #1268

Merged
merged 2 commits into from
Feb 29, 2024
Merged

Conversation

tonypartridge
Copy link
Contributor

@tonypartridge tonypartridge commented Jan 26, 2024

We were storing sensitive encrypted information and the pipe is fantastic approach and works well, but there wasn't an obvious easy way to apply it to the model for new comers to pipes etc.

Also, for anyone interested I use this pipe class to encrypt the values too

<?php

namespace App\Pipelines\Loggable;

use Closure;
use Spatie\Activitylog\Contracts\LoggablePipe;
use Spatie\Activitylog\EventLogBag;

class EncryptAttributesPipe implements LoggablePipe
{
    public function handle(EventLogBag $event, Closure $next): EventLogBag
    {
        foreach (['attributes', 'old'] as $type) {
            foreach ($event->changes[$type] ?? [] as $key => $value) {
                if ($event->model->hasCast($key, 'encrypted')) {
                    $event->changes[$type][$key] = encrypt($value);
                }
            }
        }

        return $next($event);
    }
}

@github-actions github-actions bot added the stale label Feb 17, 2024
@github-actions github-actions bot closed this Feb 25, 2024
@tonypartridge
Copy link
Contributor Author

Hmm...

@Gummibeer Gummibeer reopened this Feb 29, 2024
@Gummibeer
Copy link
Collaborator

Changed a little detail - switch to booted() method as otherwise you will have to call parent::boot() and doing so is the same as using booting() or booted().

@Gummibeer Gummibeer merged commit eb4f20e into spatie:main Feb 29, 2024
23 checks passed
@tonypartridge
Copy link
Contributor Author

tonypartridge commented Feb 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants