Better Code Gen
This commit is contained in:
parent
7eacc4863b
commit
42ff82c310
1 changed files with 14 additions and 11 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue