Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Validating Password rules with a custom error message

Using standard notation like "password.required" I can customize an error message for built-in validation rules. But how can I customize error messages for Illuminate\Validation\Rules\Password rules?

$rules = [
    'password' => [
        'required',
        'confirmed',
        Rules\Password::min(8)->letters()->mixedCase()->numbers()->symbols(),
    ],
];
$messages = [
    'password.required'  => 'يجب ادخال كلمة المرور',
    'password.confirmed' => 'كلمة المرور غير متطابقة',
];
$request->validate($rules, $messages);

How to customize the messages for min(), letters(), etc?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

According to this comment in the original pull request, you can't do this in code, and have to use the JSON localization files.

So check the validation class for the default text and then in resources/lang/ar.json add a translation for it, like so:

{
  "The :attribute must contain at least one letter.": ":attribute يجب أن يحتوي على الأقل حرف واحد.",
  "The :attribute must contain at least one uppercase and one lowercase letter.": ":attribute يجب أن يحتوي على الأقل حرف كبير واحد وحرف صغير واحد.",
  "The :attribute must contain at least one number.": ":attribute يجب أن يحتوي على الأقل رقم واحد.",
  "The :attribute must contain at least one symbol.": ":attribute يجب أن يحتوي على الأقل رمز واحد."  
}

The length message uses the standard one found in resources/lang/ar/validation.php:

<?php
return [
  "min" => [
    "string" => "يجب أن يكون طول نص حقل :attribute على الأقل :min حروفٍ/حرفًا.",
  ],
];

Or it can be declared in your code above.

$messages = [
    'password.required'  => 'يجب ادخال كلمة المرور',
    'password.confirmed' => 'كلمة المرور غير متطابقة',
    'password.min' => 'whatever',
];

Note there are packages such as Laravel Lang that can do all these translations for you.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!