Files
hoshpoint-backend/app/Http/Requests/Profile/UpdateProfileRequest.php
soheil khaledabadi 936f789ac8 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
2026-09-07 01:00:09 +03:30

70 lines
3.0 KiB
PHP

<?php
namespace App\Http\Requests\Profile;
use App\Support\Mobile;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateProfileRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
if ($this->has('mobile')) {
$this->merge(['mobile' => Mobile::normalize($this->input('mobile'))]);
}
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$userId = $this->user()->id;
return [
'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:'.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'],
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'name.required' => 'نام و نام خانوادگی الزامی است.',
'username.required' => 'نام کاربری الزامی است.',
'username.unique' => 'این نام کاربری قبلاً استفاده شده است.',
'email.required' => 'ایمیل الزامی است.',
'email.email' => 'فرمت ایمیل صحیح نیست.',
'email.unique' => 'این ایمیل قبلاً ثبت شده است.',
'mobile.required' => 'شماره موبایل الزامی است.',
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789',
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
'password.required' => 'رمز عبور الزامی است.',
'password.min' => 'رمز عبور باید حداقل ۸ کاراکتر باشد.',
'avatar.image' => 'فایل ارسالی باید تصویر باشد.',
'avatar.max' => 'حداکثر حجم تصویر ۳ مگابایت است.',
'social_links.array' => 'ساختار شبکه‌های اجتماعی نامعتبر است.',
];
}
}