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
|
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.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -23,21 +35,12 @@ class ReferralCode extends Migration
|
||||||
$existing_user = User::where('referral_code', '')->orWhere('referral_code', NULL)->get();
|
$existing_user = User::where('referral_code', '')->orWhere('referral_code', NULL)->get();
|
||||||
|
|
||||||
foreach ($existing_user as $user) {
|
foreach ($existing_user as $user) {
|
||||||
$random = STR::random(8);
|
$this->generateCode($user->id);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the migrations.
|
* Reverse the migrations.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue