Support the ongoing development of Laravel.io →
Validation

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.