diff --git a/src/app/AuthAttempt.php b/src/app/AuthAttempt.php --- a/src/app/AuthAttempt.php +++ b/src/app/AuthAttempt.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Iatstuti\Database\Support\NullableFields; +use App\Traits\UuidTrait; use Carbon\Carbon; /** @@ -14,6 +15,7 @@ class AuthAttempt extends Model { use NullableFields; + use UuidTrait; // No specific reason public const REASON_NONE = ''; @@ -43,9 +45,6 @@ 'last_seen' => 'datetime' ]; - public $incrementing = false; - protected $keyType = 'string'; - /** * Prepare a date for array / JSON serialization. * diff --git a/src/app/Observers/AuthAttemptObserver.php b/src/app/Observers/AuthAttemptObserver.php deleted file mode 100644 --- a/src/app/Observers/AuthAttemptObserver.php +++ /dev/null @@ -1,31 +0,0 @@ -{$authAttempt->getKeyName()} = $allegedly_unique; - break; - } - } - } -} diff --git a/src/app/Traits/UuidTrait.php b/src/app/Traits/UuidTrait.php new file mode 100644 --- /dev/null +++ b/src/app/Traits/UuidTrait.php @@ -0,0 +1,45 @@ +{$model->getKeyName()})) { + while (true) { + $allegedly_unique = \App\Utils::uuidStr(); + if (!$model->find($allegedly_unique)) { + $model->{$plan->getKeyName()} = $allegedly_unique; + break; + } + } + } + }); + } + + /** + * Get if the key is incrementing. + * + * @return bool + */ + public function getIncrementing() + { + return false; + } + + /** + * Get the key type. + * + * @return string + */ + public function getKeyType() + { + return 'string'; + } +}