Logger Example
Here’s a simple example of a Logger
for a Product
model:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use App\Filament\Resources\ProductResource;
use App\Models\Product;
use Illuminate\Contracts\Support\Htmlable;
use Noxo\FilamentActivityLog\Loggers\Logger;
use Noxo\FilamentActivityLog\ResourceLogger\Field;
use Noxo\FilamentActivityLog\ResourceLogger\RelationManager;
use Noxo\FilamentActivityLog\ResourceLogger\ResourceLogger;
use Spatie\Activitylog\Models\Activity;
class ProductLogger extends Logger
{
// public static bool $disabled = true;
public static ?string $model = Product::class;
public static function getLabel(): string | Htmlable | null
{
// return __('Product');
return ProductResource::getModelLabel();
}
public function getSubjectRoute(Activity $activity): ?string
{
return ProductResource::getUrl('edit', ['record' => $activity->subject_id]);
}
public function getRelationManagerRoute(Activity $activity): ?string
{
return $this->getSubjectRoute($activity).'?activeRelationManager=0';
}
public static function resource(ResourceLogger $logger): ResourceLogger
{
return $logger
// Resource Fields
->fields([
Field::make('title')
->label(__('Title')),
Field::make('categories.name')
->label(__('Categories'))
->hasMany('categories')
->badge(),
Field::make('media')
->label(__('Images'))
->media(gallery: true),
Field::make('price')
->label(__('Price'))
->money('EUR'),
Field::make('status')
->label(__('Status'))
->enum(ProductStatus::class),
Field::make('active')
->label(__('Visible'))
->boolean(),
])
// Relation Managers
->relationManagers([
RelationManager::make('accessories')
->label('Accessory')
->fields([
Field::make('name')
->label(__('Label')),
Field::make('price')
->label(__('Price'))
->money('EUR'),
]),
]);
}
}