From 3beddca69cb9523b8a2e2b82f2659e4a66a17c74 Mon Sep 17 00:00:00 2001 From: Julian Prieber <60265788+JulianPrieber@users.noreply.github.com> Date: Fri, 1 Dec 2023 17:11:35 +0100 Subject: [PATCH] Set admin account ID to always be 1 --- app/Models/User.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index cc56e1d..33061f8 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -62,18 +62,22 @@ class User extends Authenticatable implements MustVerifyEmail parent::boot(); static::creating(function ($user) { - if (config('linkstack.disable_random_user_ids') != 'true') { - $numberOfDigits = config('linkstack.user_id_length') ?? 6; + if (config('linkstack.disable_random_user_ids') != 'true') { + if (is_null(User::first())) { + $user->id = 1; + } else { + $numberOfDigits = config('linkstack.user_id_length') ?? 6; - $minIdValue = 10**($numberOfDigits - 1); - $maxIdValue = 10**$numberOfDigits - 1; + $minIdValue = 10**($numberOfDigits - 1); + $maxIdValue = 10**$numberOfDigits - 1; - do { - $randomId = rand($minIdValue, $maxIdValue); - } while (User::find($randomId)); + do { + $randomId = rand($minIdValue, $maxIdValue); + } while (User::find($randomId)); - $user->id = $randomId; - } + $user->id = $randomId; + } + } }); } }