├── .github ├── FUNDING.yml ├── resources │ ├── pxlrbt-activity-log.png │ └── screenshot.png └── workflows │ └── code-style.yml ├── .gitignore ├── LICENSE.md ├── composer.json ├── readme.md ├── resources ├── lang │ ├── ar │ │ └── activities.php │ ├── ckb │ │ └── activities.php │ ├── cs │ │ └── activities.php │ ├── de │ │ └── activities.php │ ├── en │ │ └── activities.php │ ├── es │ │ └── activities.php │ ├── fa │ │ └── activities.php │ ├── fr │ │ └── activities.php │ ├── id │ │ └── activities.php │ ├── it │ │ └── activities.php │ ├── nl │ │ └── activities.php │ ├── pt_BR │ │ └── activities.php │ └── tr │ │ └── activities.php └── views │ └── pages │ └── list-activities.blade.php └── src ├── FilamentActivityLogServiceProvider.php └── Pages └── ListActivities.php /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: pxlrbt 2 | -------------------------------------------------------------------------------- /.github/resources/pxlrbt-activity-log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pxlrbt/filament-activity-log/9956fa3ed645c46e94bbaf6bb3faecf34a41d200/.github/resources/pxlrbt-activity-log.png -------------------------------------------------------------------------------- /.github/resources/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pxlrbt/filament-activity-log/9956fa3ed645c46e94bbaf6bb3faecf34a41d200/.github/resources/screenshot.png -------------------------------------------------------------------------------- /.github/workflows/code-style.yml: -------------------------------------------------------------------------------- 1 | name: Code Style 2 | on: 3 | pull_request: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | php-cs-fixer: 10 | name: Run Laravel Pint 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: write 14 | 15 | steps: 16 | - name: Setup PHP 17 | uses: shivammathur/setup-php@v2 18 | with: 19 | php-version: '8.1' 20 | 21 | - name: Git checkout 22 | uses: actions/checkout@v3 23 | with: 24 | ref: ${{ github.head_ref }} 25 | 26 | - name: Install dependencies 27 | run: composer install -n --prefer-dist 28 | 29 | - name: Run Laravel Pint 30 | run: ./vendor/bin/pint 31 | 32 | - name: Commit changes 33 | uses: stefanzweifel/git-auto-commit-action@v4 34 | with: 35 | commit_message: Apply style changes 36 | file_pattern: '*.php' 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | .idea 6 | phpunit.xml 7 | .phpunit.result.cache 8 | .php-cs-fixer.cache 9 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [2022] [Dennis Koch] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pxlrbt/filament-activity-log", 3 | "description": "Spatie's Laravel Activity Log integrated into Filament", 4 | "license": "MIT", 5 | "keywords": [ 6 | "activity log", 7 | "filament", 8 | "laravel-filament" 9 | ], 10 | "authors": [ 11 | { 12 | "name": "Dennis Koch", 13 | "email": "info@pixelarbeit.de" 14 | } 15 | ], 16 | "require": { 17 | "php": "^8.0", 18 | "filament/filament": "^3.0.5.0", 19 | "spatie/laravel-activitylog": "^4.7" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "pxlrbt\\FilamentActivityLog\\": "src/" 24 | } 25 | }, 26 | "extra": { 27 | "laravel": { 28 | "providers": [ 29 | "\\pxlrbt\\FilamentActivityLog\\FilamentActivityLogServiceProvider" 30 | ] 31 | } 32 | }, 33 | "require-dev": { 34 | "laravel/pint": "^1.5" 35 | }, 36 | "scripts": { 37 | "pint": "vendor/bin/pint" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | ![header](./.github/resources/pxlrbt-activity-log.png) 4 | 5 |
6 | 7 | # Filament Activity Log 8 | 9 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/pxlrbt/filament-activity-log.svg?include_prereleases)](https://packagist.org/packages/pxlrbt/filament-activity-log) 10 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md) 11 | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/pxlrbt/filament-activity-log/code-style.yml?branch=main&label=Code%20style&style=flat-square) 12 | [![Total Downloads](https://img.shields.io/packagist/dt/pxlrbt/filament-activity-log.svg)](https://packagist.org/packages/pxlrbt/filament-activity-log) 13 | 14 | 15 | This package adds a page to the Filament Admin panel to view the activity log generated by [`spatie/laravel-activitylog`](https://github.com/spatie/laravel-activitylog). 16 | 17 |
18 | 19 | ![Screenshot](./.github/resources/screenshot.png) 20 | 21 |
22 | 23 | ## Installation 24 | 25 | | Plugin Version | Filament Version | PHP Version | 26 | |----------------|-----------------|-------------| 27 | | 0.1.x | 2.x | \> 8.0 | 28 | | 1.x | 3.x | \> 8.1 | 29 | 30 | Install via Composer. 31 | 32 | **Requires PHP 8.0 and Filament 2.0** 33 | 34 | ```bash 35 | composer require pxlrbt/filament-activity-log 36 | ``` 37 | 38 | > **Warning** 39 | > This plugin only offers a page to show activities related to your model. You need [`spatie/laravel-activitylog`](https://github.com/spatie/laravel-activitylog) installed and configured for it to work. It is important you are using the `LogsActivity` trait as per [Spatie's docs](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/logging-model-events) for this work as we use the '->activities()' method of the trait. 40 | 41 | ## Usage 42 | 43 | Make sure you use a **custom theme** and the vendor folder for this plugins is published, so that it includes the Tailwind CSS classes. 44 | 45 | ### Create a page 46 | 47 | Create the page inside your resources `Pages/` directory. Replace `UserResource` with your resource. 48 | 49 | ```php 50 | Pages\ListUsers::route('/'), 71 | 'create' => Pages\CreateUser::route('/create'), 72 | 'activities' => Pages\ListUserActivities::route('/{record}/activities'), 73 | 'edit' => Pages\EditUser::route('/{record}/edit'), 74 | ]; 75 | } 76 | ``` 77 | 78 | ### Link to your page 79 | 80 | Use a Filament action to link to your from your table or page. 81 | 82 | ```php 83 | $table->actions([ 84 | Action::make('activities')->url(fn ($record) => YourResource::getUrl('activities', ['record' => $record])) 85 | ]); 86 | ``` 87 | 88 | ## Contributing 89 | 90 | If you want to contribute to this packages, you may want to test it in a real Filament project: 91 | 92 | - Fork this repository to your GitHub account. 93 | - Create a Filament app locally. 94 | - Clone your fork in your Filament app's root directory. 95 | - In the `/filament-activity-log` directory, create a branch for your fix, e.g. `fix/error-message`. 96 | 97 | Install the packages in your app's `composer.json`: 98 | 99 | ```json 100 | "require": { 101 | "pxlrbt/filament-activity-log": "dev-fix/error-message as main-dev", 102 | }, 103 | "repositories": [ 104 | { 105 | "type": "path", 106 | "url": "filament-activity-log" 107 | } 108 | ] 109 | ``` 110 | 111 | Now, run `composer update`. 112 | -------------------------------------------------------------------------------- /resources/lang/ar/activities.php: -------------------------------------------------------------------------------- 1 | 'سجل عمليات', 5 | 6 | 'title' => 'سجل عمليات :record', 7 | 8 | 'default_datetime_format' => 'Y-m-d, H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'الحقل', 12 | 'old' => 'سابقاً', 13 | 'new' => 'حالياً', 14 | 'restore' => 'أسترجاع', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'تحديث', 19 | 'created' => 'إنشاء', 20 | 'deleted' => 'حذف', 21 | 'restored' => 'استعادة', 22 | 'restore_successful' => 'تم الاسترجاع بنجاح', 23 | 'restore_failed' => 'فشل الاستراجع', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/ckb/activities.php: -------------------------------------------------------------------------------- 1 | 'نرخی پێشوو', 6 | 7 | 'title' => 'نرخەکانی پێشووی :record', 8 | 9 | 'default_datetime_format' => 'Y-m-d, H:i:s', 10 | 11 | 'table' => [ 12 | 'field' => 'خانە', 13 | 'old' => 'کۆن', 14 | 'new' => 'نوێ', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'نوێکراوەتەوە', 19 | 'Created' => 'دروستکراوە', 20 | 'deleted' => 'سڕایەوە', 21 | 'restored' => 'گەڕاندنەوە', 22 | 'restore_successful' => 'بە سەرکەوتوویی گەڕێنرایەوە', 23 | 'restore_failed' => 'گەڕاندنەوە شکستی هێنا', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/cs/activities.php: -------------------------------------------------------------------------------- 1 | 'Log', 5 | 6 | 'title' => 'Log entity ":record"', 7 | 8 | 'default_datetime_format' => 'j.n.Y H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Pole', 12 | 'old' => 'Původní', 13 | 'new' => 'Nové', 14 | 'restore' => 'Obnovit', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Upraveno', 19 | 'created' => 'Vytvořeno', 20 | 'deleted' => 'Smazáno', 21 | 'restored' => 'Obnoveno', 22 | 'restore_successful' => 'Úspěšně obnoveno', 23 | 'restore_failed' => 'Obnovení selhalo', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/de/activities.php: -------------------------------------------------------------------------------- 1 | 'Historie', 5 | 6 | 'title' => 'Historie :record', 7 | 8 | 'default_datetime_format' => 'd.m.Y, H:i:s \U\h\r', 9 | 10 | 'table' => [ 11 | 'field' => 'Feld', 12 | 'old' => 'Alt', 13 | 'new' => 'Neu', 14 | 'restore' => 'Wiederherstellen', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Aktualisiert', 19 | 'created' => 'Erstellt', 20 | 'deleted' => 'Gelöscht', 21 | 'restored' => 'Wiederhergestellt', 22 | 'restore_successful' => 'Erfolgreich wiederhergestellt', 23 | 'restore_failed' => 'Wiederherstellung fehlgeschlagen', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/en/activities.php: -------------------------------------------------------------------------------- 1 | 'History', 5 | 6 | 'title' => 'History :record', 7 | 8 | 'default_datetime_format' => 'Y-m-d, H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Field', 12 | 'old' => 'Old', 13 | 'new' => 'New', 14 | 'restore' => 'Restore', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Updated', 19 | 'created' => 'Created', 20 | 'deleted' => 'Deleted', 21 | 'restored' => 'Restored', 22 | 'restore_successful' => 'Restored successfully', 23 | 'restore_failed' => 'Restore failed', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/es/activities.php: -------------------------------------------------------------------------------- 1 | 'Historial', 5 | 6 | 'title' => 'Historial :record', 7 | 8 | 'default_datetime_format' => 'd/m/Y, H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Campo', 12 | 'old' => 'Anterior', 13 | 'new' => 'Nuevo', 14 | 'restore' => 'Restaurar', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Actualizado', 19 | 'created' => 'Creado', 20 | 'deleted' => 'Eliminado', 21 | 'restored' => 'Restaurado', 22 | 'restore_successful' => 'Restauración exitosa', 23 | 'restore_failed' => 'Restauración fallida', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/fa/activities.php: -------------------------------------------------------------------------------- 1 | 'تاریخچه', 5 | 6 | 'title' => 'تاریخچه :record', 7 | 8 | 'default_datetime_format' => 'Y-m-d، H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'فیلد', 12 | 'old' => 'قدیمی', 13 | 'new' => 'جدید', 14 | 'restore' => 'بازیابی', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'به‌روزرسانی شد', 19 | 'created' => 'ایجاد شد', 20 | 'deleted' => 'حذف شد', 21 | 'restored' => 'بازیابی شد', 22 | 'restore_successful' => 'با موفقیت بازیابی شد', 23 | 'restore_failed' => 'بازیابی ناموفق بود', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/fr/activities.php: -------------------------------------------------------------------------------- 1 | 'Historique', 5 | 6 | 'title' => 'Historique :record', 7 | 8 | 'default_datetime_format' => 'd/m/Y, H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Champ', 12 | 'old' => 'Ancien', 13 | 'new' => 'Nouveau', 14 | 'restore' => 'Restaurer', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Mis à jour', 19 | 'created' => 'Créé', 20 | 'deleted' => 'Effacé', 21 | 'restored' => 'Restauré', 22 | 'restore_successful' => 'Restauré avec succès', 23 | 'restore_failed' => 'Échec de la restauration', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/id/activities.php: -------------------------------------------------------------------------------- 1 | 'Riwayat', 5 | 6 | 'title' => 'Riwayat :record', 7 | 8 | 'default_datetime_format' => 'd/m/Y H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Bagian', 12 | 'old' => 'Sebelum', 13 | 'new' => 'Sesudah', 14 | 'restore' => 'Pulihkan', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Terbarui', 19 | 'created' => 'Terbuat', 20 | 'deleted' => 'Terhapus', 21 | 'restored' => 'Terpulihkan', 22 | 'restore_successful' => 'Sukses memulihkan', 23 | 'restore_failed' => 'Gagal memulihkan', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/it/activities.php: -------------------------------------------------------------------------------- 1 | 'Cronologia', 5 | 6 | 'title' => 'Cronologia :record', 7 | 8 | 'default_datetime_format' => 'd/m/Y, H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Campo', 12 | 'old' => 'Vecchio', 13 | 'new' => 'Nuovo', 14 | 'restore' => 'Ripristina', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Aggiornato', 19 | 'created' => 'Creato', 20 | 'deleted' => 'Eliminato', 21 | 'restored' => 'Ripristinato', 22 | 'restore_successful' => 'Ripristinato con successo', 23 | 'restore_failed' => 'Ripristino fallito', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/nl/activities.php: -------------------------------------------------------------------------------- 1 | 'Geschiedenis', 5 | 6 | 'title' => 'Geschiedenis :record', 7 | 8 | 'default_datetime_format' => 'Y-m-d, H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Veld', 12 | 'old' => 'Oud', 13 | 'new' => 'Nieuw', 14 | 'restore' => 'Herstellen', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Bewerkt', 19 | 'created' => 'Aangemaakt', 20 | 'deleted' => 'Verwijderd', 21 | 'restored' => 'Hersteld', 22 | 'restore_successful' => 'Succesvol hersteld', 23 | 'restore_failed' => 'Herstellen mislukt', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/pt_BR/activities.php: -------------------------------------------------------------------------------- 1 | 'Histórico', 5 | 6 | 'title' => 'Histórico :record', 7 | 8 | 'default_datetime_format' => 'd/m/Y H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Campo', 12 | 'old' => 'Antes', 13 | 'new' => 'Depois', 14 | 'restore' => 'Restaurado', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Atualizado', 19 | 'created' => 'Criado', 20 | 'deleted' => 'Excluído', 21 | 'restored' => 'Restaurado', 22 | 'restore_successful' => 'Restaurado com sucesso', 23 | 'restore_failed' => 'Falha na restauração', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/lang/tr/activities.php: -------------------------------------------------------------------------------- 1 | 'Geçmiş', 5 | 6 | 'title' => ':record Geçmişi', 7 | 8 | 'default_datetime_format' => 'd.m.Y, H:i:s', 9 | 10 | 'table' => [ 11 | 'field' => 'Alan', 12 | 'old' => 'Eski Değer', 13 | 'new' => 'Yeni Değer', 14 | 'restore' => 'Geri Yükle', 15 | ], 16 | 17 | 'events' => [ 18 | 'updated' => 'Güncellendi', 19 | 'created' => 'Oluşturuldu', 20 | 'deleted' => 'Silindi', 21 | 'restored' => 'Geri Yüklendi', 22 | 'restore_successful' => 'Başarıyla Geri Yüklendi', 23 | 'restore_failed' => 'Geri Yükleme Başarısız', 24 | ], 25 | ]; 26 | -------------------------------------------------------------------------------- /resources/views/pages/list-activities.blade.php: -------------------------------------------------------------------------------- 1 | @php 2 | use \Illuminate\Support\Js; 3 | @endphp 4 | 5 |
6 | @foreach($this->getActivities() as $activityItem) 7 | 8 | @php 9 | /* @var \Spatie\Activitylog\Models\Activity $activityItem */ 10 | $changes = $activityItem->getChangesAttribute(); 11 | @endphp 12 | 13 |
17 |
18 |
19 |
20 | @if ($activityItem->causer) 21 | 22 | @endif 23 |
24 | {{ $activityItem->causer?->name }} 25 | 26 | @lang('filament-activity-log::activities.events.' . $activityItem->event) {{ $activityItem->created_at->format(__('filament-activity-log::activities.default_datetime_format')) }} 27 | 28 |
29 |
30 |
31 | @if ($this->canRestoreActivity() && $changes->isNotEmpty()) 32 | 40 | @lang('filament-activity-log::activities.table.restore') 41 | 42 | @endif 43 |
44 |
45 |
46 | 47 | @if ($changes->isNotEmpty()) 48 | 49 | 50 | 51 | @lang('filament-activity-log::activities.table.field') 52 | 53 | 54 | @lang('filament-activity-log::activities.table.old') 55 | 56 | 57 | @lang('filament-activity-log::activities.table.new') 58 | 59 | 60 | @foreach (data_get($changes, 'attributes', []) as $field => $change) 61 | @php 62 | $oldValue = isset($changes['old'][$field]) ? $changes['old'][$field] : ''; 63 | $newValue = isset($changes['attributes'][$field]) ? $changes['attributes'][$field] : ''; 64 | @endphp 65 | $loop->even])> 66 | 67 | {{ $this->getFieldLabel($field) }} 68 | 69 | 70 | @if(is_array($oldValue)) 71 |
{{ json_encode($oldValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}
72 | @else 73 | {{ $oldValue }} 74 | @endif 75 |
76 | 77 | @if(is_array($newValue)) 78 |
{{ json_encode($newValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}
79 | @else 80 | {{ $newValue }} 81 | @endif 82 |
83 |
84 | @endforeach 85 |
86 | @endif 87 |
88 | @endforeach 89 | 90 | 95 |
96 |
97 | -------------------------------------------------------------------------------- /src/FilamentActivityLogServiceProvider.php: -------------------------------------------------------------------------------- 1 | name(static::$name) 16 | ->hasViews() 17 | ->hasTranslations(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Pages/ListActivities.php: -------------------------------------------------------------------------------- 1 | record = $this->resolveRecord($record); 32 | } 33 | 34 | public function getBreadcrumb(): string 35 | { 36 | return static::$breadcrumb ?? __('filament-activity-log::activities.breadcrumb'); 37 | } 38 | 39 | public function getTitle(): string 40 | { 41 | return __('filament-activity-log::activities.title', ['record' => $this->getRecordTitle()]); 42 | } 43 | 44 | public function getActivities() 45 | { 46 | return $this->paginateTableQuery( 47 | $this->record->activities()->with('causer')->latest()->getQuery() 48 | ); 49 | } 50 | 51 | public function getFieldLabel(string $name): string 52 | { 53 | static::$fieldLabelMap ??= $this->createFieldLabelMap(); 54 | 55 | return static::$fieldLabelMap[$name] ?? $name; 56 | } 57 | 58 | protected function createFieldLabelMap(): Collection 59 | { 60 | $form = static::getResource()::form(new Form($this)); 61 | 62 | $components = collect($form->getComponents()); 63 | $extracted = collect(); 64 | 65 | while (($component = $components->shift()) !== null) { 66 | if ($component instanceof Field || $component instanceof MorphToSelect) { 67 | $extracted->push($component); 68 | 69 | continue; 70 | } 71 | 72 | $children = $component->getChildComponents(); 73 | 74 | if (count($children) > 0) { 75 | $components = $components->merge($children); 76 | 77 | continue; 78 | } 79 | 80 | $extracted->push($component); 81 | } 82 | 83 | return $extracted 84 | ->filter(fn ($field) => $field instanceof Field) 85 | ->mapWithKeys(fn (Field $field) => [ 86 | $field->getName() => $field->getLabel(), 87 | ]); 88 | } 89 | 90 | public function canRestoreActivity(): bool 91 | { 92 | return static::getResource()::canRestore($this->record); 93 | } 94 | 95 | public function restoreActivity(int|string $key) 96 | { 97 | if (! $this->canRestoreActivity()) { 98 | abort(403); 99 | } 100 | 101 | $activity = $this->record->activities() 102 | ->whereKey($key) 103 | ->first(); 104 | 105 | $oldProperties = data_get($activity, 'properties.old'); 106 | 107 | if ($oldProperties === null) { 108 | $this->sendRestoreFailureNotification(); 109 | 110 | return; 111 | } 112 | 113 | try { 114 | $this->record->update($oldProperties); 115 | 116 | $this->sendRestoreSuccessNotification(); 117 | } catch (Exception $e) { 118 | $this->sendRestoreFailureNotification($e->getMessage()); 119 | } 120 | } 121 | 122 | protected function sendRestoreSuccessNotification(): Notification 123 | { 124 | return Notification::make() 125 | ->title(__('filament-activity-log::activities.events.restore_successful')) 126 | ->success() 127 | ->send(); 128 | } 129 | 130 | protected function sendRestoreFailureNotification(?string $message = null): Notification 131 | { 132 | return Notification::make() 133 | ->title(__('filament-activity-log::activities.events.restore_failed')) 134 | ->body($message) 135 | ->danger() 136 | ->send(); 137 | } 138 | 139 | protected function getIdentifiedTableQueryStringPropertyNameFor(string $property): string 140 | { 141 | return $property; 142 | } 143 | 144 | protected function getDefaultTableRecordsPerPageSelectOption(): int 145 | { 146 | return 10; 147 | } 148 | 149 | protected function getTableRecordsPerPageSelectOptions(): array 150 | { 151 | return [10, 25, 50]; 152 | } 153 | } 154 | --------------------------------------------------------------------------------