pxlrbt/filament-activity-log
Installation Run:
composer require pxlrbt/filament-activity-log
Publish the config (if needed):
php artisan vendor:publish --provider="Pxlrbt\FilamentActivityLog\FilamentActivityLogServiceProvider"
Basic Setup
Ensure spatie/laravel-activitylog is installed (this package wraps it for Filament).
Register the package in AppServiceProvider:
use Pxlrbt\FilamentActivityLog\FilamentActivityLogServiceProvider;
public function boot()
{
$this->app->register(FilamentActivityLogServiceProvider::class);
}
First Use Case
Log an activity for a model (e.g., Post):
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
class Post extends Model
{
use LogsActivity;
protected static $logAttributes = ['title', 'content'];
protected static $logOnly = ['title'];
}
Access logs in Filament via the Activity Log widget or page.
Model Logging
LogsActivity trait on Eloquent models.$logAttributes, $logOnly, or $logExcept.class User extends Model
{
use LogsActivity;
protected static $logAttributes = ['name', 'email'];
protected static $logOnly = ['email'];
}
Manual Logging Trigger logs manually:
use Spatie\Activitylog\Facades\Activity;
Activity::log('custom_event', $user, ['custom_data' => 'value']);
Filament Integration
use Pxlrbt\FilamentActivityLog\Widgets\ActivityLogWidget;
Dashboard::widget(ActivityLogWidget::class);
use Pxlrbt\FilamentActivityLog\Pages\ActivityLogPage;
Route::get('/activity-log', ActivityLogPage::class)->name('filament.activity-log');
Filtering & Search
Use Filament’s built-in filters (e.g., by model, user, or event) via the UI.
Customize query scopes in config/filament-activity-log.php:
'query' => [
'default' => fn ($query) => $query->where('properties->user_id', auth()->id()),
],
Real-Time Updates Combine with Laravel Echo/Pusher for live log updates (extend the widget).
ActivityLog with custom events:
Activity::performing('custom_event', function ($model) {
return ['metadata' => $model->metadata];
});
spatie/laravel-activitylog is configured for soft deletes if needed:
'should_log_soft_deletes' => true,
Missing spatie/laravel-activitylog
composer require spatie/laravel-activitylog).Permission Issues
view activity logs permission by default.use Filament\Permissions\PermissionsPolicy;
$policy = app(PermissionsPolicy::class);
$policy->userCan('view activity logs', fn ($user) => $user->isAdmin());
Performance with Large Logs
'perPage' => 20, // in config/filament-activity-log.php
activity_logs table:
php artisan activitylog:install
Event Naming Conflicts
created, updated) may clash with custom events.Activity::log('user.updated_profile', $user);
Model Not Logging
$logAttributes is set and the model uses LogsActivity.Logs Not Appearing?
spatie/laravel-activitylog logs:
tail -f storage/logs/laravel.log | grep activity
Activity::log('test_event', new User);
Filament Widget Blank?
php artisan filament:cache-reset
Custom Data Not Saved
properties are serialized correctly:
Activity::log('event', $model, ['key' => 'value']);
config/activitylog.php properties_to_log includes your keys.Customize Log Display Override the widget’s table columns:
use Pxlrbt\FilamentActivityLog\Widgets\ActivityLogWidget;
ActivityLogWidget::make()
->table([
'id',
'log_name',
'properties->custom_field',
]);
Add Actions to Logs
Extend the ActivityLogPage to add buttons (e.g., "Revert"):
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->columns([...])
->actions([
Tables\Actions\Action::make('revert')
->action(fn ($record) => /* logic */),
]);
}
Export Logs
Use Filament’s export method:
public static function getPages(): array
{
return [
'export' => ActivityLogPage::class,
];
}
Webhook Notifications Trigger events on log creation:
Activity::performing('*', function ($model) {
event(new ActivityLogged($model));
});
Multi-Tenant Logs Scope logs to tenant ID:
'query' => [
'default' => fn ($query) => $query->where('properties->tenant_id', tenant()->id),
],
How can I help you explore Laravel packages today?