laravel unique id code example
Example 1: laravel generate unique token
use Illuminate\Support\Str;
public function yourFunction(){
$var = Str::random(32);
dd($var);
}
Example 2: laravel rule unique where
'required|email|unique:company_users,email_address,NULL,id,company_id,' . $request->company_id
Example 3: laravel unique id
function generateBarcodeNumber() {
$number = mt_rand(1000000000, 9999999999);
if (barcodeNumberExists($number)) {
return generateBarcodeNumber();
}
return $number;
}
function barcodeNumberExists($number) {
return User::whereBarcodeNumber($number)->exists();
}