0
votes

I'm trying to translate my error message in to french. But the validation message contains in the

app/Rules/MatchOldPassword.php file

I have translated the error messages in validation.php file, but how can I translate this error message which is in a different route

Here is my code for MatchOldPassword.php

<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Hash;

class MatchOldPassword implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return Hash::check($value, auth()->user()->password);
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute need to be matched the with old password.';
    }
}
1

1 Answers

1
votes

Use the __ method for string translation

/**
 * Get the validation error message.
 *
 * @return string
 */
public function message()
{
    return __('validation.<key>'); // the key is the key specified in your validation file
}