1. Go to this page and download the library: Download wedevelopnl/audit-log library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use WeDevelop\AuditLog\Event\AbstractAuditEvent;
use WeDevelop\AuditLog\Event\Changeset;
use WeDevelop\AuditLog\Event\FieldChange;
use WeDevelop\AuditLog\Event\Subject;
final readonly class UserRoleChanged extends AbstractAuditEvent
{
public function __construct(
private string $userId,
private string $from,
private string $to,
) {
}
public function code(): string
{
return 'user.role_changed';
}
public function subject(): Subject
{
return new Subject(User::class, $this->userId);
}
public function changes(): Changeset
{
return new Changeset(FieldChange::of('role', $this->from, $this->to));
}
protected function parameters(): array
{
return ['from' => $this->from, 'to' => $this->to];
}
}