Skip to content

Commit 1921854

Browse files
anteriovieira@gmail.comanteriovieira@gmail.com
authored andcommitted
Auditoria adicionada para registros criados
1 parent aca30db commit 1921854

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/OwenIt/Auditing/Auditing.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public static function boot()
5959
$model->auditUpdate();
6060
});
6161

62+
static::created(function($model)
63+
{
64+
$model->auditCreation();
65+
});
66+
6267
static::deleted(function($model)
6368
{
6469
$model->prepareAudit();
@@ -126,6 +131,25 @@ public function prepareAudit()
126131
}
127132
}
128133

134+
/**
135+
* Audit creation
136+
*/
137+
public function auditCreation()
138+
{
139+
if ((!isset($this->auditEnabled) || $this->auditEnabled))
140+
{
141+
return $this->audit([
142+
'old_value' => null,
143+
'new_value' => $this->updatedData,
144+
'owner_type' => get_class($this),
145+
'owner_id' => $this->getKey(),
146+
'user_id' => $this->getUserId(),
147+
'created_at' => new \DateTime(),
148+
'updated_at' => new \DateTime(),
149+
]);
150+
}
151+
}
152+
129153
/**
130154
* Listener pos save
131155
*/

src/OwenIt/Auditing/AuditingTrait.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public static function bootAuditingTrait()
5252
$model->auditUpdate();
5353
});
5454

55+
static::created(function($model)
56+
{
57+
$model->auditCreation();
58+
});
59+
5560
static::deleted(function($model)
5661
{
5762
$model->prepareAudit();
@@ -118,6 +123,25 @@ public function prepareAudit()
118123
}
119124
}
120125

126+
/**
127+
* Audit creation
128+
*/
129+
public function auditCreation()
130+
{
131+
if ((!isset($this->auditEnabled) || $this->auditEnabled))
132+
{
133+
return $this->audit([
134+
'old_value' => null,
135+
'new_value' => $this->updatedData,
136+
'owner_type' => get_class($this),
137+
'owner_id' => $this->getKey(),
138+
'user_id' => $this->getUserId(),
139+
'created_at' => new \DateTime(),
140+
'updated_at' => new \DateTime(),
141+
]);
142+
}
143+
}
144+
121145
/**
122146
* Listener pos save
123147
*/

0 commit comments

Comments
 (0)