Skip to content

Commit 3beddca

Browse files
committed
Set admin account ID to always be 1
1 parent 712101c commit 3beddca

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

app/Models/User.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,22 @@ protected static function boot()
6262
parent::boot();
6363

6464
static::creating(function ($user) {
65-
if (config('linkstack.disable_random_user_ids') != 'true') {
66-
$numberOfDigits = config('linkstack.user_id_length') ?? 6;
65+
if (config('linkstack.disable_random_user_ids') != 'true') {
66+
if (is_null(User::first())) {
67+
$user->id = 1;
68+
} else {
69+
$numberOfDigits = config('linkstack.user_id_length') ?? 6;
6770

68-
$minIdValue = 10**($numberOfDigits - 1);
69-
$maxIdValue = 10**$numberOfDigits - 1;
71+
$minIdValue = 10**($numberOfDigits - 1);
72+
$maxIdValue = 10**$numberOfDigits - 1;
7073

71-
do {
72-
$randomId = rand($minIdValue, $maxIdValue);
73-
} while (User::find($randomId));
74+
do {
75+
$randomId = rand($minIdValue, $maxIdValue);
76+
} while (User::find($randomId));
7477

75-
$user->id = $randomId;
76-
}
78+
$user->id = $randomId;
79+
}
80+
}
7781
});
7882
}
7983
}

0 commit comments

Comments
 (0)