Skip to content

Instantly share code, notes, and snippets.

@aynm142
Created May 18, 2018 11:49
Show Gist options
  • Save aynm142/9b851861d8fce5bb44ff92bc530c4b96 to your computer and use it in GitHub Desktop.
Save aynm142/9b851861d8fce5bb44ff92bc530c4b96 to your computer and use it in GitHub Desktop.
user.php
public function activateCode(Request $request)
{
$code = $request->get('promo_code');
if ($this->user->activation_code || $this->user->promo_code_first == $code || $this->user->promo_code_second == $code) {
return response()->json([], 405);
}
$referral = User::wherePromoCodeFirst($code)->first();
$referral_second = User::wherePromoCodeSecond($code)->first();
if ($referral || $referral_second) {
$this->user->activation_code = $code;
$this->user->referrer_id = ($referral) ? $referral->id : $referral_second->id
$this->user->save();
} else {
return response()->json([], 404);
}
return response()->json([], 200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment