PHP code example of bokshorn-it / filament-activity-timeline

1. Go to this page and download the library: Download bokshorn-it/filament-activity-timeline 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/ */

    

bokshorn-it / filament-activity-timeline example snippets


use BokshornIt\FilamentActivityTimeline\ActivityTimelinePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugin(ActivityTimelinePlugin::make());
}

use BokshornIt\FilamentActivityTimeline\Contracts\ProvidesActivityTitle;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

class Article extends Model implements ProvidesActivityTitle
{
    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logFillable()
            ->logOnlyDirty()
            ->dontSubmitEmptyLogs();
    }

    public function activityTitle(): ?string
    {
        return $this->title;
    }
}

return LogOptions::defaults()
    ->logUnguarded()
    ->logExcept(['created_at', 'updated_at'])
    ->logOnlyDirty()
    ->dontSubmitEmptyLogs();

use BokshornIt\FilamentActivityTimeline\Actions\ActivityTimelineAction;

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

ActivityTimelineAction::make()
    ->withRelations(['revisions', 'comments'])
    ->limit(25)

return [
    'author_id' => 'Author',
    'due_date' => 'Due date',
    'published_at' => 'Published',
];

use BokshornIt\FilamentActivityTimeline\Contracts\ProvidesActivityValues;

class Article extends Model implements ProvidesActivityValues
{
    public function formatActivityValue(string $key, mixed $value): ?string
    {
        if (str_ends_with($key, '_cents')) {
            return Number::currency((int) $value / 100, 'EUR');
        }

        return null;
    }
}

activity()
    ->performedOn($article)
    ->causedBy($user)
    ->event('published')
    ->log('published');

ActivityTimelinePlugin::make()
    ->events([
        'published' => ['icon' => 'heroicon-m-globe-alt', 'color' => 'success'],
        'archived' => ['icon' => 'heroicon-m-archive-box', 'color' => 'gray'],
        'escalated' => ['icon' => 'heroicon-m-arrow-trending-up', 'color' => 'warning'],
    ])

return [
    'article_revision' => 'Revision',
    'line_item' => 'Line item',
];

ActivityTimelinePlugin::make()
    ->causerIcons([
        User::class => 'heroicon-m-user',
        Customer::class => 'heroicon-m-building-office',
        ApiClient::class => 'heroicon-m-cpu-chip',
    ])
    ->systemCauserIcon('heroicon-m-cog-6-tooth')

activity()->withoutLogs(fn () => $this->import($rows));

ActivityTimelinePlugin::make()
    ->restorable([
        Article::class,
        Category::class,
    ])

ActivityTimelinePlugin::make()
    ->modifyQueryUsing(fn (Builder $query) => $query
        ->where('tenant_id', Filament::getTenant()?->getKey()))

ActivityTimelinePlugin::make()
    ->navigationGroup(fn (): string => __('navigation.group.system'))
    ->navigationIcon('heroicon-o-archive-box')
    ->navigationSort(10)
    ->registerNavigation(false) // hide it but keep the routes

use BokshornIt\FilamentActivityTimeline\Policies\ActivityPolicy;
use Spatie\Activitylog\Models\Activity;

Gate::policy(Activity::class, ActivityPolicy::class);

class AuditResource extends ActivityResource
{
    public static function getModelLabel(): string
    {
        return __('audit.model.singular');
    }
}

ActivityTimelinePlugin::make()->resource(AuditResource::class);

ActivityTimelinePlugin::make()
    ->ignoredKeys(['search_index'])   // never show these in a diff
    ->dateFormat('d.m.Y')
    ->dateTimeFormat('d.m.Y H:i')
    ->timelineLimit(50)
    ->placeholder('-')
css
@source '../../../../vendor/bokshorn-it/filament-activity-timeline/resources/**/*.blade.php';
bash
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-activity-timeline-config"
bash
php artisan vendor:publish --tag="filament-activity-timeline-views"
php artisan vendor:publish --tag="filament-activity-timeline-translations"