Add base logic for audit logging
This commit is contained in:
parent
9684456480
commit
b15679d3bb
3 changed files with 177 additions and 0 deletions
|
@ -50,6 +50,7 @@ use Znck\Eloquent\Traits\BelongsToThrough;
|
|||
* @property \Pterodactyl\Models\ServerTransfer $transfer
|
||||
* @property \Pterodactyl\Models\Backup[]|\Illuminate\Database\Eloquent\Collection $backups
|
||||
* @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts
|
||||
* @property \Pterodactyl\Models\AuditLog[] $audits
|
||||
*/
|
||||
class Server extends Model
|
||||
{
|
||||
|
@ -326,4 +327,29 @@ class Server extends Model
|
|||
{
|
||||
return $this->hasManyThrough(Mount::class, MountServer::class, 'server_id', 'id', 'id', 'mount_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves an audit entry to the database for the server.
|
||||
*
|
||||
* @param string $action
|
||||
* @param array $metadata
|
||||
* @return \Pterodactyl\Models\AuditLog
|
||||
*/
|
||||
public function audit(string $action, array $metadata): AuditLog
|
||||
{
|
||||
$model = AuditLog::factory($action, $metadata)->fill([
|
||||
'server_id' => $this->id,
|
||||
]);
|
||||
$model->save();
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function audits()
|
||||
{
|
||||
return $this->hasMany(AuditLog::class);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue