Implement superadmin audit log for mutations
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
namespace App\Filament\Blog\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\CategoryResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\Pages\AuditedCreateRecord;
|
||||
|
||||
class CreateCategory extends CreateRecord
|
||||
class CreateCategory extends AuditedCreateRecord
|
||||
{
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
@@ -30,4 +30,4 @@ class CreateCategory extends CreateRecord
|
||||
|
||||
$this->record = static::getResource()::getModel()::create($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,23 @@
|
||||
namespace App\Filament\Blog\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\CategoryResource;
|
||||
use App\Filament\Resources\Pages\AuditedEditRecord;
|
||||
use App\Services\Audit\SuperAdminAuditLogger;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCategory extends EditRecord
|
||||
class EditCategory extends AuditedEditRecord
|
||||
{
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\DeleteAction::make()
|
||||
->after(fn ($record) => app(SuperAdminAuditLogger::class)->recordModelMutation(
|
||||
'deleted',
|
||||
$record,
|
||||
source: static::class
|
||||
)),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -24,7 +30,7 @@ class EditCategory extends EditRecord
|
||||
'description_de' => 'nullable|string',
|
||||
'name_en' => 'nullable|string|max:255',
|
||||
'description_en' => 'nullable|string',
|
||||
'slug' => 'required|string|max:255|unique:blog_categories,slug,' . $this->record->id,
|
||||
'slug' => 'required|string|max:255|unique:blog_categories,slug,'.$this->record->id,
|
||||
'is_visible' => 'boolean',
|
||||
];
|
||||
}
|
||||
@@ -40,12 +46,13 @@ class EditCategory extends EditRecord
|
||||
public function save(bool $shouldRedirect = true, bool $shouldSendSavedNotification = true): void
|
||||
{
|
||||
$state = $this->form->getState();
|
||||
\Illuminate\Support\Facades\Log::info('EditCategory Save - Full State:', $state);
|
||||
|
||||
$data = $state['data'] ?? $state;
|
||||
|
||||
$data = \App\Filament\Blog\Resources\CategoryResource::mutateFormDataBeforeSave($data);
|
||||
|
||||
$this->record->update($data);
|
||||
|
||||
parent::afterSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user