Code Sample:
$numberOfCode = 20;
for ($i = 1; $i <= $numberOfCode; $i++) {
$insArr[] = array(
'code' => substr(md5(microtime()), rand(1, 26), 6),
'created_at' => date('Y-m-d H:i:s'),
);
}
\App\ActivationCode::insert($insArr);
Hi, I am generating random codes and save it to db. But the code must have to be unique. This code need to be unique at $insArr array as well as at code column of activation_codes table. How can I do this using laravel validation rules? Thanks.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community