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

Feature: Callback to map values #8

Open
pxlrbt opened this issue Aug 2, 2023 · 1 comment
Open

Feature: Callback to map values #8

pxlrbt opened this issue Aug 2, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@pxlrbt
Copy link
Owner

pxlrbt commented Aug 2, 2023

Callback to map values formatState() or similar for display.

@pxlrbt pxlrbt added the enhancement New feature or request label Aug 2, 2023
@digitall-it
Copy link

I was searching exactly for this feature, here's a proposal on how it could work and remain consistent with the LogsActivity trait in spatie/laravel-activitylog:

<?php

namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use pxlrbt\FilamentActivityLog\Pages\ListActivities;

class ListUserActivities extends ListActivities
{
    protected static string $resource = UserResource::class;
    
    public function tapActivity(Activity $activity, string $eventName): void    {}
}

the use case is that you don't want to actually change the properties in the database while logging, just the way they are shown on the screen (for example to fetch relationship names, format dates, a meaningful display of structured data).

Suggesting to use tapActivity in the model instead would mess up this package "Restore" feature, because it is used to actually replace the changed data. For things like dates and times it may be OK but for structured data or relationship names it wouldn't work anymore.

The feature is implemented in the spatie package like this if (method_exists($model, 'tapActivity')) {$logger->tap([$model, 'tapActivity'], $eventName);} and could become something like if (method_exists($this, 'tapActivity')) {$logger->tap([$model, 'tapActivity'], $eventName);} somewhere in ListActivities.php.

What's your stance on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants