Better Code Gen

This commit is contained in:
Dennis 2022-06-07 10:18:33 +02:00 committed by GitHub
parent 7eacc4863b
commit 42ff82c310
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,18 @@ use Illuminate\Support\Str;
class ReferralCode extends Migration
{
public function generateCode($userid){
$random = STR::random(8);
if (User::where('referral_code', '=', $random)->doesntExist()) {
DB::table("users")
->where("id", "=", $userid)
->update(['referral_code' => $random]);
}else{
$this->generateCode($userid);
}
}
/**
* Run the migrations.
*
@ -23,19 +35,10 @@ class ReferralCode extends Migration
$existing_user = User::where('referral_code', '')->orWhere('referral_code', NULL)->get();
foreach ($existing_user as $user) {
$random = STR::random(8);
if (User::where('referral_code', '=', $random)->doesntExist()) {
DB::table("users")
->where("id", "=", $user->id)
->update(['referral_code' => $random]);
}else{
$random = STR::random(8);
DB::table("users")
->where("id", "=", $user->id)
->update(['referral_code' => $random]);
$this->generateCode($user->id);
}
}
}
/**