PHP code example of asignua / filament-activity-log-plus

1. Go to this page and download the library: Download asignua/filament-activity-log-plus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asignua / filament-activity-log-plus example snippets


use Asignua\FilamentActivityLogPlus\ActivityLogPlusPlugin;

$panel->plugin(
    ActivityLogPlusPlugin::make()
        ->authorizeResource(fn (): bool => auth()->user()?->isAdmin() ?? false),
);

use Asignua\FilamentActivityLogPlus\Concerns\LogsActivityPlus;

class Post extends Model
{
    use LogsActivityPlus; // instead of spatie's LogsActivity, which it 

protected function activityExcept(): array { return ['api_secret']; }          // your own secrets
protected function activityTranslatableAttributes(): array { return ['title']; } // see below
protected function activityIgnoreOnlyChanged(): array { return ['path']; }     // derived columns

protected function activityTranslatableAttributes(): array
{
    return ['title', 'summary'];
}

activity()->withoutLogging(fn () => $this->rebuildLinks());

app(ActivityBatch::class)->run(function () use ($post): void {
    $post->update([...]);
    $post->syncAndLog('tags', $ids);
});

use Asignua\FilamentActivityLogPlus\Concerns\LogsPivotSync;

class Post extends Model
{
    use LogsActivityPlus;
    use LogsPivotSync;
}

$post->syncAndLog('tags', [1, 2, 3]);        // returns sync()'s result

// or, for anything else (attach/detach, a custom pivot):
PivotSynced::dispatch($post, 'tags', attached: [3], detached: [1]);

PivotTitles::using(fn (string $relation, array $ids, Model $owner): array => [...]); // [id => title]

MediaAdapters::register(
    MediaAttachment::class,
    owner: fn (MediaAttachment $a): ?Model => $a->attachable,
    properties: fn (MediaAttachment $a): array => ['name' => $a->file?->name],
    events: ['created' => 'media_attached', 'deleted' => 'media_detached'],
);

activity()
    ->performedOn($application)
    ->event('approved')
    ->withProperties(['note' => 'Looks fine'])
    ->log('approved');

ActivityEvents::register(
    'approved',
    'Approved',                                           // a translation key or a ready string, or a closure
    color: 'success',                                     // a Filament colour
    summary: fn (Activity $a): string => (string) $a->getProperty('note'),
    view: 'my-app::activity.approved',                    // optional: replaces the body of the card
);

use Asignua\FilamentActivityLogPlus\Actions\ActivityHistoryAction;

protected function getHeaderActions(): array
{
    return [ActivityHistoryAction::make(), DeleteAction::make()];
}

ActivityLogPlusPlugin::make()
    ->navigationGroup('System')
    ->navigationSort(8)
    ->navigationIcon('heroicon-o-clipboard-document-list')
    ->resource(false); // History action only

ActivityLogPlusPlugin::make()
    ->authorizeResource(fn (): bool => auth()->user()?->isAdmin())  // the log resource
    ->authorizeHistory(fn (): bool => true);                        // the History action

Gate::define('activity-log-plus.view', fn (User $user): bool => $user->isAdmin());

'schedule' => ['enabled' => true, 'time' => '03:30'],
bash
php artisan vendor:publish --tag=filament-activity-log-plus-migrations
bash
php artisan migrate
bash
php artisan vendor:publish --tag=filament-activity-log-plus-config
bash
php artisan filament:assets
bash
php artisan activity-log-plus:prune            # retention_days (365)
php artisan activity-log-plus:prune --days=90