【问题标题】:Error message translation issue in laravellaravel 中的错误消息翻译问​​题
【发布时间】:2020-04-06 03:50:55
【问题描述】:

我正在尝试将我的错误信息翻译成法语。但验证消息包含在

app/Rules/MatchOldPassword.php文件

我已经翻译了validation.php文件中的错误信息,但是我如何翻译这个在不同路径中的错误信息

这是我的 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.';
    }
}

【问题讨论】:

    标签: php laravel translation laravel-6 rules


    【解决方案1】:

    使用__方法进行字符串翻译

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

    【讨论】:

    • 工作。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 2020-01-05
    • 2019-07-27
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多