diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index dad5e72..6a45cb1 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -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'; +} + diff --git a/app/Models/Contact.php b/app/Models/Contact.php index c843206..469cc04 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -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)); + }); + } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 9e12e02..21ee769 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -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)); + }); + } }