用于扩展自定义验证程序类的Laravel错误消息

时间:2015-07-24 13:03:46

标签: laravel

这是我的验证服务提供商。

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Services\Validation\CustomValidation;

class ValidationServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        // We don't have to register anything here so we keep this empty!
    }

    /**
     * Boot the service provider.
     */
    public function boot()
    {
        // Need to override the default validator with our own validator
        // We can do that by using the resolver function
        $this->app->validator->resolver(function ($translator, $data, $rules, $messages) {
            // This class will hold all our custom validations
            return new CustomValidation($translator, $data, $rules, $messages);
        });
    }
}

这是扩展Laravel验证器类的自定义验证类。我很困惑我应该在哪里编写自定义规则的错误消息。我可以找到任何文件。

<?php namespace App\Services\Validation;

use Illuminate\Support\Facades\DB;
use Illuminate\Validation\Validator;

class CustomValidation extends Validator
{
    /**
     * $attribute Input name
     * $value Input value
     * $parameters Table, field1
     */
    public function validateCustomRule($attribute, $value, $parameters)
    {
        // Logic to be written later
        return false;
    }
}

1 个答案:

答案 0 :(得分:0)

您是否尝试使用相同的约定将它们添加到验证语言文件中? &#39; custom_rule&#39; =&GT; &#39;一些消息&#39;