// SYSTEM PANEL //
[ROOT]
/
mnt
/
pleskStorage
/
vhosts
/
kodsolutions.net
/
subdomains
/
go-rent.kodsolutions.net
/
app
/
Helpers
[ PARENT ]
EDIT :: GenerateCode.php
<?php namespace App\Helpers; use Illuminate\Support\Str; use Illuminate\Support\Facades\Config; class GenerateCode { public static function generate($model, $attribute, $digit, $str = false) { $uniqueStr = ''; $from = 1; $to = 9; if ($str) { $uniqueStr = Str::random($digit); } else { for ($i = 0; $i < $digit; $i++) { $from += $from * 10; $to = $to . '9'; } $uniqueStr = random_int((int)$from, (int)$to); } while ($model::where($attribute, $uniqueStr)->exists()) { if ($str) { $uniqueStr = Str::random($digit); } else { $uniqueStr = random_int((int)$from, (int)$to); } } return $uniqueStr; } }
SAVE
CANCEL