Add audit trail middleware and model listeners
This commit is contained in:
@@ -6,9 +6,14 @@ use App\Http\Requests\PermissionRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
use App\Models\Permission;
|
||||
use App\Services\Logging\ActivityLogger;
|
||||
|
||||
class PermissionController extends Controller
|
||||
{
|
||||
public function __construct(private readonly ActivityLogger $logger)
|
||||
{
|
||||
}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
$permissions = Permission::orderBy('name')->get();
|
||||
@@ -23,6 +28,12 @@ class PermissionController extends Controller
|
||||
'guard_name' => 'web',
|
||||
]);
|
||||
|
||||
$this->logger->audit([
|
||||
'action' => 'permission_created',
|
||||
'model' => 'Permission',
|
||||
'changes' => ['name' => $request->input('name')],
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Permission berhasil ditambahkan.');
|
||||
}
|
||||
|
||||
@@ -30,6 +41,13 @@ class PermissionController extends Controller
|
||||
{
|
||||
$permission->update(['name' => $request->input('name')]);
|
||||
|
||||
$this->logger->audit([
|
||||
'action' => 'permission_updated',
|
||||
'model' => 'Permission',
|
||||
'model_id' => $permission->id,
|
||||
'changes' => ['name' => $permission->name],
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Permission berhasil diperbarui.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user