Skip to content

Commit

Permalink
Don't touch updated_by if unauthenticated
Browse files Browse the repository at this point in the history
Don't clear updated_by if the current user is not
authenticated. Allows setting updated_by in factories.

Fix #16
  • Loading branch information
22Nick22 committed Jun 2, 2021
1 parent d9849e5 commit 1006784
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/AuditableTraitObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Yajra\Auditable;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;

class AuditableTraitObserver
{
Expand Down Expand Up @@ -59,7 +58,7 @@ public function saved(Model $model)
{
$updatedBy = $model->getUpdatedByColumn();

if ($model->$updatedBy <> $this->getAuthenticatedUserId()) {
if ($this->getAuthenticatedUserId() && $model->$updatedBy <> $this->getAuthenticatedUserId()) {
$model->$updatedBy = $this->getAuthenticatedUserId();
$model->save();
}
Expand Down

0 comments on commit 1006784

Please sign in to comment.