added hash to contact and invoice

pull/44/head
A1Gard 3 months ago
parent 1082906bf5
commit 0e338e44a1

@ -491,3 +491,26 @@ function formatFileSize($size) {
return number_format($size / 1073741824, 1) . ' GB';
}
}
/**
* generating hash UID by length
* @param $length
* @return string
*/
function generateUniqueID($length = 8) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$uniqueID = '';
for ($i = 0; $i < $length; $i++) {
$randomChar = $chars[rand(0, strlen($chars) - 1)];
$uniqueID .= $randomChar;
}
return $uniqueID;
}
function getSetting(){
return 'test@xshop.ir';
}

@ -8,4 +8,18 @@ use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
use HasFactory;
public function getRouteKeyName()
{
return 'hash';
}
protected static function boot()
{
parent::boot();
static::creating(function($model) {
$model->hash = generateUniqueID((strlen(Contact::count()) + 2));
});
}
}

@ -8,4 +8,19 @@ use Illuminate\Database\Eloquent\Model;
class Invoice extends Model
{
use HasFactory;
public function getRouteKey()
{
return 'hash';
}
protected static function boot()
{
parent::boot();
static::creating(function($model) {
$model->hash = generateUniqueID( (strlen(Invoice::count()) + 2));
});
}
}

Loading…
Cancel
Save