Files
hatame.andarza09/app/Http/Requests/ProfileUpdateRequest.php
T
hatame d43e74b280 git add .
git commit "add profile image upload support"
2026-08-16 11:37:20 +03:30

133 lines
3.1 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ProfileUpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$user = auth()->user();
return [
'first_name' => [
'required',
'persian_alpha',
'string',
'max:255'
],
'last_name' => [
'required',
'persian_alpha',
'string',
'max:255'
],
'national_code' => [
'required',
'ir_national_id',
Rule::unique('users', 'national_code')
->ignore($user->id),
],
'gender' => [
'required',
'in:0,1'
],
'marital_status' => [
'required',
'in:0,1,2'
],
'spouse_name' => [
'nullable',
'string',
'persian_alpha',
'max:255',
'required_if:marital_status,1',
],
'mobile' => [
'required',
'ir_mobile',
Rule::unique('users','mobile')
->ignore($user->id)
],
'email' => [
'required',
'email',
Rule::unique('users','email')
->ignore($user->id)
],
'username' => [
'required',
'string',
'regex:/^[A-Za-z0-9]+$/',
Rule::unique('users','username')->ignore($user->id)
],
'profile_image' => [
'nullable',
'image',
'mimes:jpg,jpeg,png,webp',
'max:800',
],
'province_id' => [
'nullable',
'exists:provinces,id',
],
'city_id' => [
'nullable',
Rule::exists('cities', 'id')
->where(fn ($query) => $query->where('province_id', $this->province_id)),
],
'password' => [
'required',
'confirmed',
'min:8'
],
'current_password' => [
'required_with:new_password',
'current_password:web',
],
'new_password' => [
'nullable',
'string',
'min:8',
'confirmed',
],
'new_password_confirmation' => [
'nullable',
'string',
],
];
}
}