### Install package with Composer Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Installs the package via Composer. ```bash composer require rmsramos/activitylog ``` -------------------------------- ### Run activitylog:install command Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Runs the install command to publish config and migrations from spatie/laravel-activitylog. ```bash php artisan activitylog:install ``` -------------------------------- ### Run database migrations Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Runs the database migrations. ```bash php artisan migrate ``` -------------------------------- ### Publish activitylog views Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Optionally publishes the views. ```bash php artisan vendor:publish --tag="activitylog-views" ``` -------------------------------- ### Publish activitylog config Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Manually publishes the configuration file. ```bash php artisan vendor:publish --tag="activitylog-config" ``` -------------------------------- ### Configure ActivitylogPlugin with all options Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Shows the full configuration of the ActivitylogPlugin in a Filament panel. It sets a custom resource, labels, navigation options, authorization, translation, date parsing and formatting, and action visibility. Note the trailing comma after the translateSubject call, which is present in the source. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->resource(\Path\For\Your\CustomResource::class) ->label('Log') ->pluralLabel('Logs') ->navigationItem(true) ->navigationGroup('Activity Log') ->navigationIcon('heroicon-o-shield-check') ->navigationCountBadge(true) ->navigationSort(2) ->authorize( fn () => auth()->user()->id === 1 ) ->translateSubject(fn($label) => __("yourCustomLangFile.".$label)), ->dateParser( fn($date) => auth()->user()->isJalaliCalendar() ? Jalalian::fromDateTime($date) : Carbon::parse($date) ) ->dateFormat('Y-m-d') ->datetimeFormat(fn() => auth()->user()->getFilamentDateTimeFormat()) ->customizeDatetimeColumn(function ($column) { return $column->when( auth()->user()->isJalaliCalendar(), function ($column) { return $column->jalaliDateTime(); } ); }) ->customizeDatePicker(function ($field) { return $field->when( auth()->user()->isJalaliCalendar(), function ($field) { return $field->jalali(); } ); }) ->isRestoreActionHidden(true) ->isResourceActionHidden(true) ->isRestoreModelActionHidden(false) ->resourceActionLabel("Sample Label"), ]); } ``` -------------------------------- ### Rebuild assets with npm Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Rebuilds your assets after adding the @source directive. ```bash npm run build ``` -------------------------------- ### Show Restore (Soft Deletes) with isRestoreModelActionHidden Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Show the restore (soft delete) action for activity log entries. First, set 'subject_returns_soft_deleted_models' to true in config/activitylog.php, then use isRestoreModelActionHidden(false) in the ActivitylogPlugin to globally display the restore action. ```php return [ 'subject_returns_soft_deleted_models' => true, ] ``` ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->isRestoreModelActionHidden(false) ]); } ``` -------------------------------- ### Configure ActivityLogTimelineTableAction with relations, icons, and limit Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Configure the ActivityLogTimelineTableAction in a Filament resource's table method. Use withRelations to include related models, timelineIcons and timelineIconColors to customize icons and colors for created/updated events, and limit to cap the number of timeline entries. ```php use Rmsramos\Activitylog\Actions\ActivityLogTimelineTableAction; public static function table(Table $table): Table { return $table ->actions([ ActivityLogTimelineTableAction::make('Activities') ->withRelations(['profile', 'address']) ->timelineIcons([ 'created' => 'heroicon-m-check-badge', 'updated' => 'heroicon-m-pencil-square', ]) ->timelineIconColors([ 'created' => 'info', 'updated' => 'warning', ]) ->limit(10), ]); } ``` -------------------------------- ### Customize ActivitylogPlugin label and pluralLabel Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Customize the resource label and plural label by setting the `->label()` and `->pluralLabel()` values on the ActivitylogPlugin. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->label('Log') ->pluralLabel('Logs'), ]); } ``` -------------------------------- ### Basic Spatie ActivityLog usage in a model Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Add the LogsActivity trait to your model and configure the getActivitylogOptions method to log only the 'name' and 'text' attributes. This enables automatic activity logging for the model. ```php use Illuminate\Database\Eloquent\Model; use Spatie\Activitylog\Traits\LogsActivity; use Spatie\Activitylog\LogOptions; class NewsItem extends Model { use LogsActivity; protected $fillable = ['name', 'text']; public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly(['name', 'text']); } } ``` -------------------------------- ### Published activitylog config file Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Contents of the published config file. Includes resource settings, navigation options, and date/datetime formats. ```php return [ 'resources' => [ 'label' => 'Activity Log', 'plural_label' => 'Activity Logs', 'hide_restore_action' => false, 'restore_action_label' => 'Restore', 'hide_resource_action' => false, 'hide_restore_model_action' => true, 'resource_action_label' => 'View', 'navigation_item' => true, 'navigation_group' => null, 'navigation_icon' => 'heroicon-o-shield-check', 'navigation_sort' => null, 'default_sort_column' => 'id', 'default_sort_direction' => 'desc', 'navigation_count_badge' => false, 'resource' => \Rmsramos\Activitylog\Resources\Activitylog\ActivitylogResource::class, ], 'date_format' => 'd/m/Y', 'datetime_format' => 'd/m/Y H:i:s', ]; ``` -------------------------------- ### Translate Activity Log Key Names with translateLogKey Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Add a translateLogKey callback within the ActivitylogPlugin chain to translate activity log key names. The callback receives the label and should return the translated string, e.g., using Laravel's __() helper with a custom language file. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->translateLogKey(fn($label) => __("yourCustomLangFile.".$label)), ]); } ``` -------------------------------- ### Customize ActivitylogResource with custom resource Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Customize the ActivitylogResource by passing your custom resource class to the resource() method. Extend the original ActivitylogResource and update the getPages method if you change the List and View pages. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->resource(\Path\For\Your\CustomResource::class), ]); } ``` -------------------------------- ### Activate ActivitylogPlugin in Filament panel Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Activate the ActivitylogPlugin in your Filament panel service provider by adding it to the plugins array. This enables the activity log resource in your panel. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make(), ]); } ``` -------------------------------- ### Toggle ActivitylogPlugin navigationItem Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Enable or disable the resource navigation item by setting `->navigationItem(false)`. The default value is true. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->navigationItem(false), // by default is true ]); } ``` -------------------------------- ### Customize timeline icons and colors Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Customize the icons and colors for the timeline action. Defaults are 'heroicon-m-check' icon and 'primary' color. ```php use Rmsramos\Activitylog\Actions\ActivityLogTimelineTableAction; public static function table(Table $table): Table { return $table ->actions([ ActivityLogTimelineTableAction::make('Activities') ->timelineIcons([ 'created' => 'heroicon-m-check-badge', 'updated' => 'heroicon-m-pencil-square', ]) ->timelineIconColors([ 'created' => 'info', 'updated' => 'warning', ]) ]); } ``` -------------------------------- ### Set navigation sort with ActivitylogPlugin Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Set the navigation sort order for the activity log resource by passing an integer to the `navigationSort()` method in the `ActivitylogPlugin` chain. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->navigationSort(3), ]); } ``` -------------------------------- ### Hide Restore / View Action with isRestoreActionHidden and isResourceActionHidden Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Hide the restore and view actions globally for a resource within the ActivitylogPlugin using isRestoreActionHidden and isResourceActionHidden. Also customize the label of the view action with resourceActionLabel. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->isRestoreActionHidden(true) ->isResourceActionHidden(true) ->resourceActionLabel("Sample Label") ]); } ``` -------------------------------- ### Enable navigation count badge with ActivitylogPlugin Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Enable the count badge on the activity log navigation item by setting the `navigationCountBadge()` method to `true` in the `ActivitylogPlugin` chain. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->navigationCountBadge(true), ]); } ``` -------------------------------- ### Translate resource names with ActivitylogPlugin Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Translate resource names in the activity log by adding a `translateSubject` callback to the `ActivitylogPlugin` chain. The callback receives the subject label and returns a translated string using Laravel's `__()` helper. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->translateSubject(fn($label) => __("yourCustomLangFile.".$label)), ]); } ``` -------------------------------- ### Configure withRelations on ActivityLogTimelineTableAction Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Pass a matrix of relationships to the ActivityLogTimelineTableAction using withRelations(). Remember to configure your Models. ```php public static function table(Table $table): Table { return $table ->actions([ ActivityLogTimelineTableAction::make('Activities') ->withRelations(['profile', 'address']), //opcional ]); } ``` -------------------------------- ### Limit timeline results with limit() Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Limit the number of results in the timeline query. By default, the last 10 records are returned. ```php use Rmsramos\Activitylog\Actions\ActivityLogTimelineTableAction; public static function table(Table $table): Table { return $table ->actions([ ActivityLogTimelineTableAction::make('Activities') ->limit(30), ]); } ``` -------------------------------- ### Set ActivitylogPlugin navigationGroup Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Add a navigation group to the resource by setting the `->navigationGroup()` value. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->navigationGroup('Activity Log'), ]); } ``` -------------------------------- ### Authorize access to activity log with ActivitylogPlugin Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Restrict access to the activity log resource by adding an `authorize` callback to the `ActivitylogPlugin` chain. The callback returns `true` only for the user with ID 1. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->authorize( fn () => auth()->user()->id === 1 ), ]); } ``` -------------------------------- ### Add ActivityLogTimelineTableAction to table Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Add the ActivityLogTimelineTableAction to a Filament resource's table actions to enable a timeline view of activity logs. ```php use Rmsramos\Activitylog\Actions\ActivityLogTimelineTableAction; public static function table(Table $table): Table { return $table ->actions([ ActivityLogTimelineTableAction::make('Activities'), ]); } ``` -------------------------------- ### Role Policy for ActivitylogResource with Gate::policy Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Ensure ActivitylogResource access via RolePolicy by registering a Gate policy for the Activity model in the AppServiceProvider's boot method. ```php use App\Policies\ActivityPolicy; use Illuminate\Support\Facades\Gate; use Spatie\Activitylog\Models\Activity; class AppServiceProvider extends ServiceProvider { public function boot(): void { Gate::policy(Activity::class, ActivityPolicy::class); } } ``` -------------------------------- ### Customize Date and DateTime Formats with dateFormat and datetimeFormat Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Customize the format of date and datetime columns using dateFormat and datetimeFormat methods. The datetimeFormat callback can return a format string based on user settings, e.g., getFilamentDateTimeFormat(). ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->dateFormat('Y-m-d') ->datetimeFormat(fn() => auth()->user()->getFilamentDateTimeFormat()) ]); } ``` -------------------------------- ### Manipulate View Action Using HasCustomActivityResource Trait Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Implement getFilamentActualResourceModel in the HasCustomActivityResource trait to determine the actual model related to the activity record for generating valid URLs. The method inspects the translatable subject and returns the corresponding model, throwing an exception if the class is not recognized. ```php use Rmsramos\Activitylog\Traits\HasCustomActivityResource; trait HasCustomActivityResource { public function getFilamentActualResourceModel($record) { $record = $record->subject->translatable; $model = null; switch ($record::class) { case FirstTranslatableModel::class: $model = $record->firstModel; break; case SecondTranslatableModel::class: $model = $record->secondModel; break; default: throw new Exception("Error Translatable subject model not found. record = ".$record::class, 1); break; } return $model; } } ``` -------------------------------- ### Customize ActivitylogPlugin navigationIcon Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Customize the resource navigation icon by setting the `->navigationIcon()` value. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->navigationIcon('heroicon-o-shield-check'), ]); } ``` -------------------------------- ### Customize Date Parsing with dateParser Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Customize how dates are parsed using the dateParser callback. The callback receives the date and can return a Jalalian or Carbon instance based on user preferences, e.g., checking isJalaliCalendar(). ```php use Rmsramos\Activitylog\ActivitylogPlugin; use Morilog\Jalali\Jalalian; use Carbon\Carbon; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->dateParser( fn($date) => auth()->user()->isJalaliCalendar() ? Jalalian::fromDateTime($date) : Carbon::parse($date) ) ]); } ``` -------------------------------- ### Customize Date Picker Fields with customizeDatePicker Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Customize date picker fields in Filament forms based on user preferences. The closure receives the field and conditionally applies the jalali() method when the authenticated user uses the Jalali calendar. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->customizeDatePicker(function ($field) { return $field->when( auth()->user()->isJalaliCalendar(), function ($field) { return $field->jalali(); } ); }) ]); } ``` -------------------------------- ### Customize DateTime Columns with customizeDatetimeColumn Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Conditionally customize datetime columns in the UI using the customizeDatetimeColumn callback. The callback receives the column and can apply transformations like jalaliDateTime() when the user prefers the Jalali calendar. ```php use Rmsramos\Activitylog\ActivitylogPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ ActivitylogPlugin::make() ->customizeDatetimeColumn(function ($column) { return $column->when( auth()->user()->isJalaliCalendar(), function ($column) { return $column->jalaliDateTime(); } ); }) ]); } ``` -------------------------------- ### Add ActivitylogRelationManager to Filament resource Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Add the ActivitylogRelationManager to a Filament resource's getRelations() method to display activity logs for models using the LogsActivity trait. ```php use Rmsramos\Activitylog\RelationManagers\ActivitylogRelationManager; public static function getRelations(): array { return [ ActivitylogRelationManager::class, ]; } ``` -------------------------------- ### Add @source directive for Tailwind v4 Source: https://github.com/rmsramos/activitylog/blob/3.x/README.md Add this @source directive to your panel's theme.css (e.g. resources/css/filament/admin/theme.css) so Tailwind v4 scans the package's Blade views. Without it, the Timeline Action modal renders without icon badges, timeline line, and spacing. ```css @source '../../../../vendor/rmsramos/activitylog/resources/**/*'; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.