Skip to content

Commit

Permalink
Merge pull request #29 from markusreis-yd/main
Browse files Browse the repository at this point in the history
__clone method called on non-object
  • Loading branch information
JohnathonKoster authored Nov 27, 2023
2 parents 8e3570d + a220568 commit e6b30e2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Listeners/BaseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ abstract class BaseListener
protected function checkForDatabaseObject($object)
{
if ($object instanceof User || (method_exists($object, 'model') && method_exists($object, 'toModel'))) {
$object = $object->model();
// If model() returns null (eg. on create), fallback to $object, as `clone null` will throw an exception
$object = $object->model() ?: $object;
}

return clone $object;
}
}
}

0 comments on commit e6b30e2

Please sign in to comment.