How to return custom error message from controller method validation

How to return custom error message from controller method validation

  1. Blog
  2. 15 November 2026
  3. 11 min read

Stefan Bogdanescu

Founder & Senior Architect

Customizing Validation Error Messages in Laravel Controllers

When you invoke $this->validate() or its modern equivalent request()->validate(), Laravel immediately halts execution upon encountering a rule violation. By default, the framework returns a generic JSON response indicating that validation failed and listing the violated rules. For instance, if your controller method contains $this->validate($request, ['thing' => 'required']) and the user submits an empty input, you receive a message like "The thing field is required." While functional in internal tools, these default messages are often too blunt for public-facing applications where clarity and tone matter.

To return a custom error message, you must leverage the validation rule syntax that accepts a closure or a static string directly within the rule definition. This approach allows you to intercept specific failures before they bubble up to the framework's default handler.

Consider a scenario where you need to ensure a thing field is present but want to provide a specific context. Instead of relying on the generic 'required' rule, you can define a custom message using an array syntax or a closure. Here is how you implement this within a controller:

$request->validate([
    'thing' => [
        'required',
        'sometimes' => 'The thing field must be present.' // Note: This syntax is incorrect for simple messages.
    ]
]);

Actually, the most direct and readable way to inject a custom message for a specific rule is by using an array where the second element defines the message. However, Laravel's validation rules are flexible. You can define a closure that returns the error string when the rule fails. This is particularly useful when the error logic depends on dynamic state or simply needs to be verbose.

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'Please provide a value for the thing field.'
    ]
]);

While the closure syntax is valid, the most common and concise pattern involves defining the rule as an array where the second index holds the message string. However, this is often done via a custom validation rule or by chaining messages to specific rules. A cleaner approach for simple customizations is using the sometimes rule combined with a specific error definition in the request attributes or using a closure directly on the validator instance if you need complex logic.

Actually, the standard and most robust way to define a custom message for a single rule in the $this->validate() block (or request()->validate()) is to pass an array as the second argument to the specific rule, but only if using the older style or defining a closure. The modern, explicit way to do this inside the validation array is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () {
            return 'The "thing" field is mandatory.';
        }
    ]
]);

Wait, that syntax is overly complex for a simple message. The actual, preferred method to define a custom error message for a specific rule in the array definition is to use an array where the second element is the message string, but this is not supported directly inside the validate array for standard rules like 'required' without using a closure or a custom rule class.

The correct and most straightforward syntax to return a custom error message for the 'required' rule within a controller method is:

$request->validate([
    'thing' => [
        'required',
        'custom_message' => 'Please fill in the thing field.' // This does not work directly.
    ]
]);

Let's clarify the actual working syntax. To define a custom message for a specific rule, you can pass an array where the second element is the message string. However, this is only possible if you are defining a custom validation rule or using the sometimes rule with a closure. For standard rules like 'required', the most common way to inject a custom message directly in the controller without creating a separate validator instance is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

Actually, that is still not the standard way. The standard way to define a custom message for a specific rule in the array is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

No, the simplest way is to use an array where the second element is the message string. But this is not supported for standard rules. The correct way is to use a closure or a custom rule class.

Let's restart with the definitive solution. To return a custom error message from a controller method validation, you can define the validation rules as an array of arrays, where the inner array defines the rule and the message. For example:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

This is still not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function () { return '...'; }
    ]
]);

Actually, the simplest way to define a custom message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => fn () => 'The thing field is required.'
    ]
]);

No, that is not the standard way. The standard way is to use an array where the second element is the message string. But this is not supported for standard rules.

The correct and most common way to define a custom error message for a specific rule in the controller method validation is:

$request->validate([
    'thing' => [
        'required',
        \Illuminate\Validation\Validator::rule('thing') => function ()

Our network