* @since February 2025 */ class UpdateProfileRequest extends FormRequest { /** * Determine if the user is authorized to make this request. */ public function authorize(): bool { return Auth::check(); } /** * Get the validation rules that apply to the request. */ public function rules(): array { return [ 'first_name' => [ 'required', 'string', 'min:2', 'max:50', 'regex:/^[a-zA-ZÀ-ÿ\s\-\'\.]+$/', ], 'last_name' => [ 'required', 'string', 'min:2', 'max:50', 'regex:/^[a-zA-ZÀ-ÿ\s\-\'\.]+$/', ], 'phone' => [ 'nullable', 'string', 'min:10', 'max:20', 'regex:/^[\+]?[0-9\s\-\(\)]+$/', ], 'bio' => [ 'nullable', 'string', 'max:1000', ], 'website' => [ 'nullable', 'url', 'max:255', 'regex:/^https?:\/\/.+$/', ], 'linkedin' => [ 'nullable', 'url', 'max:255', 'regex:/^https:\/\/(www\.)?linkedin\.com\/in\/[a-zA-Z0-9\-]+\/?$/', ], 'github' => [ 'nullable', 'url', 'max:255', 'regex:/^https:\/\/(www\.)?github\.com\/[a-zA-Z0-9\-]+\/?$/', ], 'twitter' => [ 'nullable', 'url', 'max:255', 'regex:/^https:\/\/(www\.)?twitter\.com\/[a-zA-Z0-9_]+\/?$/', ], ]; } /** * Get custom error messages for validation rules. */ public function messages(): array { return [ 'first_name.required' => 'First name is required.', 'first_name.regex' => 'First name contains invalid characters.', 'last_name.required' => 'Last name is required.', 'last_name.regex' => 'Last name contains invalid characters.', 'phone.regex' => 'Please enter a valid phone number.', 'website.regex' => 'Website URL must start with http:// or https://', 'linkedin.regex' => 'Please enter a valid LinkedIn profile URL.', 'github.regex' => 'Please enter a valid GitHub profile URL.', 'twitter.regex' => 'Please enter a valid Twitter profile URL.', ]; } /** * Prepare the data for validation. */ protected function prepareForValidation(): void { $this->merge([ 'first_name' => ucfirst(strtolower(trim($this->first_name ?? ''))), 'last_name' => ucfirst(strtolower(trim($this->last_name ?? ''))), 'phone' => $this->phone ? preg_replace('/[^\+0-9]/', '', $this->phone) : null, 'bio' => $this->bio ? trim($this->bio) : null, 'website' => $this->website ? strtolower(trim($this->website)) : null, 'linkedin' => $this->linkedin ? strtolower(trim($this->linkedin)) : null, 'github' => $this->github ? strtolower(trim($this->github)) : null, 'twitter' => $this->twitter ? strtolower(trim($this->twitter)) : null, ]); } }