Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Activity Model resolution #45

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ use Spatie\Activitylog\Models\Activity;
class AuthServiceProvider extends ServiceProvider
{
protected $policies = [
// Update `Activity::class` with the one defined in `config/activitylog.php`
Activity::class => ActivityPolicy::class,
];
//...
}
```
> If you are using [Shield](https://filamentphp.com/plugins/shield) just register the ActivityPolicy generated by it

## Activity Model resolution
The main `Activity` class being used by the Filament Resource instance will be resolved by Spatie's service provider, which loads the model defined by the configuration key found at `activitylog.activity_model` in `config/activitylog.php`.

## Screenshots
![filament-logger-index](https://user-images.githubusercontent.com/75579178/201537725-47361eb2-aa13-4493-a4d0-af0dde0f4eeb.png)
![filament-logger-detail](https://user-images.githubusercontent.com/75579178/201537729-51b96eed-aa24-42ed-88f6-4683337f7d81.png)
Expand Down
28 changes: 28 additions & 0 deletions resources/lang/it/filament-logger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Navigation & Resource
|--------------------------------------------------------------------------
*/

'nav.group' => 'Impostazioni',
'nav.log.label' => 'Registro attività',
'nav.log.icon' => 'heroicon-o-clipboard-list',
'resource.label.log' => 'Log',
'resource.label.logs' => 'Log',
'resource.label.user' => 'User',
'resource.label.subject' => 'Soggetto',
'resource.label.subject_type' => 'Tipo di soggetto',
'resource.label.description' => 'Descrizione',
'resource.label.type' => 'Tipologia',
'resource.label.event' => 'Evento',
'resource.label.logged_at' => 'Registrato Il',
'resource.label.properties' => 'Proprietà',
'resource.label.old' => 'Prima',
'resource.label.new' => 'Ora',
'resource.label.old_value' => 'Valore Precedente',
'resource.label.new_value' => 'Nuovo Valore',
];
9 changes: 7 additions & 2 deletions src/Resources/ActivityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Spatie\Activitylog\Models\Activity;
use Spatie\Activitylog\Contracts\Activity;
use Spatie\Activitylog\ActivitylogServiceProvider;
use Z3d0X\FilamentLogger\Resources\ActivityResource\Pages;

class ActivityResource extends Resource
{
protected static ?string $model = Activity::class;
protected static ?string $label = 'Activity Log';
protected static ?string $slug = 'activity-logs';

Expand Down Expand Up @@ -229,6 +229,11 @@ public static function getPages(): array
];
}

public static function getModel(): string
{
return ActivitylogServiceProvider::determineActivityModel();
}

protected static function getSubjectTypeList(): array
{
if (config('filament-logger.resources.enabled', true)) {
Expand Down