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:
2026-09-07 01:00:09 +03:30
parent 46ae711a20
commit 936f789ac8
38 changed files with 756 additions and 39 deletions

View File

@@ -6,23 +6,57 @@ use Illuminate\Foundation\Http\FormRequest;
class UpdateNotificationPreferencesRequest extends FormRequest
{
/**
* @var list<string>
*/
private const FIELDS = [
'comment_on_presentation',
'form_reply',
'new_follower',
'news_announcements',
'weekly_product_updates',
'weekly_blog_digest',
];
public function authorize(): bool
{
return true;
}
/**
* Accept "true"/"false"/"1"/"0"/1/0 strings from the frontend and coerce them to
* real booleans before validation so the toggles actually persist.
*/
protected function prepareForValidation(): void
{
$normalized = [];
foreach (self::FIELDS as $field) {
if ($this->has($field)) {
$normalized[$field] = filter_var($this->input($field), FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE) ?? false;
}
}
if ($normalized !== []) {
$this->merge($normalized);
}
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return array_fill_keys(self::FIELDS, ['sometimes', 'boolean']);
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'comment_on_presentation' => ['sometimes', 'boolean'],
'form_reply' => ['sometimes', 'boolean'],
'new_follower' => ['sometimes', 'boolean'],
'news_announcements' => ['sometimes', 'boolean'],
'weekly_product_updates' => ['sometimes', 'boolean'],
'weekly_blog_digest' => ['sometimes', 'boolean'],
'*.boolean' => 'مقدار این تنظیم باید بله یا خیر باشد.',
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Http\Requests\Auth;
use App\Support\Mobile;
use Illuminate\Foundation\Http\FormRequest;
class RegisterRequest extends FormRequest
@@ -11,6 +12,13 @@ class RegisterRequest extends FormRequest
return true;
}
protected function prepareForValidation(): void
{
if ($this->has('mobile')) {
$this->merge(['mobile' => Mobile::normalize($this->input('mobile'))]);
}
}
/**
* @return array<string, mixed>
*/
@@ -18,7 +26,7 @@ class RegisterRequest extends FormRequest
{
return [
'name' => ['required', 'string', 'max:255'],
'mobile' => ['required', 'string', 'regex:/^09\d{9}$/', 'unique:users,mobile'],
'mobile' => ['required', 'string', 'regex:'.Mobile::REGEX, 'unique:users,mobile'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
'password' => ['required', 'string', 'min:8'],
];
@@ -32,7 +40,7 @@ class RegisterRequest extends FormRequest
return [
'name.required' => 'نام و نام خانوادگی الزامی است.',
'mobile.required' => 'شماره موبایل الزامی است.',
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست.',
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789',
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
'email.required' => 'ایمیل الزامی است.',
'email.email' => 'فرمت ایمیل صحیح نیست.',

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Http\Requests\Profile;
use Illuminate\Foundation\Http\FormRequest;
class DeleteAccountRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'password' => ['required', 'string', 'current_password'],
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'password.required' => 'برای حذف حساب کاربری، وارد کردن رمز عبور الزامی است.',
'password.current_password' => 'رمز عبور واردشده صحیح نیست.',
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Http\Requests\Profile;
use App\Support\Mobile;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
@@ -12,6 +13,13 @@ class UpdateProfileRequest extends FormRequest
return true;
}
protected function prepareForValidation(): void
{
if ($this->has('mobile')) {
$this->merge(['mobile' => Mobile::normalize($this->input('mobile'))]);
}
}
/**
* @return array<string, mixed>
*/
@@ -23,10 +31,16 @@ class UpdateProfileRequest extends FormRequest
'name' => ['sometimes', 'required', 'string', 'max:255'],
'username' => ['sometimes', 'required', 'string', 'max:255', Rule::unique('users', 'username')->ignore($userId)],
'email' => ['sometimes', 'required', 'string', 'email', 'max:255', Rule::unique('users', 'email')->ignore($userId)],
'mobile' => ['sometimes', 'required', 'string', 'regex:/^09\d{9}$/', Rule::unique('users', 'mobile')->ignore($userId)],
'mobile' => ['sometimes', 'required', 'string', 'regex:'.Mobile::REGEX, Rule::unique('users', 'mobile')->ignore($userId)],
'password' => ['sometimes', 'required', 'string', 'min:8'],
'avatar' => ['sometimes', 'nullable', 'image', 'max:3072'],
'is_public' => ['sometimes', 'nullable', 'boolean'],
'social_links' => ['sometimes', 'nullable', 'array'],
'social_links.instagram' => ['nullable', 'string', 'max:255'],
'social_links.telegram' => ['nullable', 'string', 'max:255'],
'social_links.linkedin' => ['nullable', 'string', 'max:255'],
'social_links.twitter' => ['nullable', 'string', 'max:255'],
'social_links.website' => ['nullable', 'string', 'max:255'],
];
}
@@ -43,12 +57,13 @@ class UpdateProfileRequest extends FormRequest
'email.email' => 'فرمت ایمیل صحیح نیست.',
'email.unique' => 'این ایمیل قبلاً ثبت شده است.',
'mobile.required' => 'شماره موبایل الزامی است.',
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست.',
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789',
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
'password.required' => 'رمز عبور الزامی است.',
'password.min' => 'رمز عبور باید حداقل ۸ کاراکتر باشد.',
'avatar.image' => 'فایل ارسالی باید تصویر باشد.',
'avatar.max' => 'حداکثر حجم تصویر ۳ مگابایت است.',
'social_links.array' => 'ساختار شبکه‌های اجتماعی نامعتبر است.',
];
}
}