Page MenuHomePhorge

D2779.1775499476.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D2779.1775499476.diff

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 @@
-<?php
-
-namespace App\Observers;
-
-use App\AuthAttempt;
-
-/**
- * This is an observer for the AuthAttempt model definition.
- */
-class AuthAttemptObserver
-{
- /**
- * Handle the "creating" event on an AuthAttempt.
- *
- * Ensures that the entry uses a custom ID (uuid).
- *
- * @param AuthAttempt $authAttempt The AuthAttempt being created.
- *
- * @return void
- */
- public function creating(AuthAttempt $authAttempt)
- {
- while (true) {
- $allegedly_unique = \App\Utils::uuidStr();
- if (!AuthAttempt::find($allegedly_unique)) {
- $authAttempt->{$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 @@
+<?php
+
+namespace App\Traits;
+
+trait UuidTrait
+{
+ /**
+ * Boot function from Laravel.
+ */
+ protected static function boot()
+ {
+ parent::boot();
+ static::creating(function ($model) {
+ if (empty($model->{$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';
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 6, 6:17 PM (3 h, 45 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18838734
Default Alt Text
D2779.1775499476.diff (2 KB)

Event Timeline