Skip to content

Instantly share code, notes, and snippets.

@apocsve
Created October 19, 2016 23:02
Show Gist options
  • Save apocsve/f29ddaff34af1e585db43311c8ded4ea to your computer and use it in GitHub Desktop.
Save apocsve/f29ddaff34af1e585db43311c8ded4ea to your computer and use it in GitHub Desktop.
if (empty($this->code)) {
$options = [
'length' => 10,
'prefix' => 'GCC',
'letters' => true,
'numbers' => true,
'mask' => '-XXXXXXX-XXX'
];
$code = GCCodeGenerator::generate($options);
$gc = GiftCard::where('code', $code)->first();
while($gc)
{
$code = GCCodeGenerator::generate(10, $options);
$gc = GiftCard::where('code', $code)->first();
}
$this->times_used = 0;
$this->code = $code;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment