added pargar 4
This commit is contained in:
+32
-2
@@ -171,9 +171,39 @@ class Customer extends Authenticatable implements JWTSubject
|
||||
|
||||
public static function normalizeMobile(?string $mobile): ?string
|
||||
{
|
||||
$mobile = trim((string) $mobile);
|
||||
$digits = preg_replace('/\D+/', '', trim((string) $mobile));
|
||||
if ($digits === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $mobile === '' ? null : $mobile;
|
||||
if (str_starts_with($digits, '98') && strlen($digits) >= 12) {
|
||||
$digits = substr($digits, 2);
|
||||
}
|
||||
|
||||
$digits = ltrim($digits, '0');
|
||||
if ($digits === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return '0' . $digits;
|
||||
}
|
||||
|
||||
public static function findActiveByMobile(?string $mobile, ?int $exceptId = null): ?self
|
||||
{
|
||||
$mobile = self::normalizeMobile($mobile);
|
||||
if ($mobile === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$query = static::query()
|
||||
->whereNull('deleted_at')
|
||||
->where('mobile', $mobile);
|
||||
|
||||
if ($exceptId !== null) {
|
||||
$query->where('id', '<>', $exceptId);
|
||||
}
|
||||
|
||||
return $query->first();
|
||||
}
|
||||
|
||||
public static function isMobileTaken(?string $mobile, ?int $exceptId = null): bool
|
||||
|
||||
Reference in New Issue
Block a user