Answers for "eloquent unique column"

PHP
2

Laravel Validate unique column

'business_name' => 'required|unique:companies,name',
Posted by: Guest on August-31-2021
0

laravel unique id

function generateBarcodeNumber() {
    $number = mt_rand(1000000000, 9999999999); // better than rand()

    // call the same function if the barcode exists already
    if (barcodeNumberExists($number)) {
        return generateBarcodeNumber();
    }

    // otherwise, it's valid and can be used
    return $number;
}

function barcodeNumberExists($number) {
    // query the database and return a boolean
    // for instance, it might look like this in Laravel
    return User::whereBarcodeNumber($number)->exists();
}
Posted by: Guest on February-22-2021

Code answers related to "eloquent unique column"

Browse Popular Code Answers by Language