feat: Persian panel/API fixes and structural-model tweaks
- lang/fa: add validation/auth/passwords/pagination translations so admin and API validation errors are in Persian - templates: soft-delete instead of cascade-deleting their generations; keep resolving trashed template on generations (labels/downloads) - templates: add TemplateInfolist with a real thumbnail ImageEntry - generations: auto-name template-based generations and use that name for the download file and as a searchable column - admin: show all dates as Jalali via ->jalaliDate()/->jalaliDateTime() Filament macros (App\Support\Jalali) - wallets: harden the deposit/withdraw action to surface the exact error instead of a 500 - profile: normalize Iranian mobile numbers (App\Support\Mobile), add social_links, coerce notification-preference booleans, require the current password to delete an account Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013P66ea1dC5CVM9t29496t5
This commit is contained in:
41
app/Support/Mobile.php
Normal file
41
app/Support/Mobile.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
/**
|
||||
* Normalizes Iranian mobile numbers to the canonical "09XXXXXXXXX" form so that the
|
||||
* frontend can send numbers with Persian/Arabic digits, spaces, dashes or a country
|
||||
* code (+98 / 0098 / 98) without tripping the validation regex.
|
||||
*/
|
||||
class Mobile
|
||||
{
|
||||
public const REGEX = '/^09\d{9}$/';
|
||||
|
||||
public static function normalize(?string $value): ?string
|
||||
{
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$digits = strtr(trim($value), [
|
||||
'۰' => '0', '۱' => '1', '۲' => '2', '۳' => '3', '۴' => '4',
|
||||
'۵' => '5', '۶' => '6', '۷' => '7', '۸' => '8', '۹' => '9',
|
||||
'٠' => '0', '١' => '1', '٢' => '2', '٣' => '3', '٤' => '4',
|
||||
'٥' => '5', '٦' => '6', '٧' => '7', '٨' => '8', '٩' => '9',
|
||||
]);
|
||||
|
||||
$digits = preg_replace('/[^\d+]/', '', $digits) ?? '';
|
||||
|
||||
if (str_starts_with($digits, '+98')) {
|
||||
$digits = '0'.substr($digits, 3);
|
||||
} elseif (str_starts_with($digits, '0098')) {
|
||||
$digits = '0'.substr($digits, 4);
|
||||
} elseif (str_starts_with($digits, '98') && strlen($digits) === 12) {
|
||||
$digits = '0'.substr($digits, 2);
|
||||
} elseif (strlen($digits) === 10 && str_starts_with($digits, '9')) {
|
||||
$digits = '0'.$digits;
|
||||
}
|
||||
|
||||
return $digits === '' ? null : $digits;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user