Laravel: User-defined method valiate in Request?

I use Laravel and have validate code in Request:

class InformationsRequest extends Request
{
    // validate rule
    public function rules()
    {
        return [
            'title' => 'required|max:2000',
            'description' => 'required|max:5000'
        ];
    }

    // custom message
    public function messages()
    {
        return [
            'title.required' => 'aaa',
            'description.required' => 'bbb',
        ];
    }
}

Today, please help me 2 points:

  1. How I make user-defined validate. (checkXXX method)

Method checkXXX maybe has 1 param, 2 param .....

public function rules()
{
    return [
        'title' => 'required|max:2000|checkXXX',
        'description' => 'required|max:5000'
    ];
}
  1. Custom message for checkXXX method

Answers


You can add custom validator rules in a service provider. There's more information on this in the docs.

Validator::extend('checkXXX', function ($attribute, $value, $parameters, $validator) {
    return $attribute === true;
});

Simply return false from the callback if the attribute fails validation.

Then, provide the custom message in either your lang files, or return one from the messages() method.

return [
    'title.checkXXX' => 'The :field failed the checkXXX rule.'
];

Need Your Help

What does eigenvalues represent in Face Recognition by Eigenfaces

matlab pca eigenvector eigenvalue

I've got a set of training face images (40 images). Each image size is 28*34. From there, I'm able to get eigenVector, Score, Latent using princomp function in Matlab.

socket.io client not receiving broadcasts from server

node.js socket.io

I have an instant messaging chat application in the making, and am having problems getting my client to receive data from my server. Could anyone explain to me why this is happening?