How to show error message below input field in blade file - Laravel

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# How to Show Specific Validation Errors Below Input Fields in Laravel Blade As a senior developer working with Laravel, you frequently encounter the need to provide clear, context-specific feedback to users when form validation fails. The method you are currently using—collecting all errors into a single alert box—is functional but lacks the user experience (UX) required for good form handling. Users need to know *exactly* which field they need to correct, not just that the entire submission failed. This post will guide you through the proper Laravel and Blade techniques to display validation errors directly beneath their respective input fields, along with explaining where and how to define custom error messages. ## The Limitation of Grouped Error Display Your current approach uses `$errors->all()` to aggregate all failures into one large alert box. While this informs the user that something is wrong, it forces them to scan a long list, which is inefficient. For optimal UX, we want to associate each error message directly with the input element it pertains to. To achieve field-specific error display, we need to iterate through the input fields and check if an error exists for that specific field name. ## Solution: Displaying Field-Specific Errors in Blade The key to solving this lies in iterating over the fields present in your form (or manually checking each field) and using the `error()` helper or direct access to the `$errors` collection within the Blade file. Here is a practical example demonstrating how to display errors below their corresponding inputs: ```html
{{-- Display error specific to the 'name' field --}} @error('name')
{{ $message }}
@enderror
{{-- Display error specific to the 'email' field --}} @error('email')
{{ $message }}
@enderror
{{-- Display error specific to the 'password' field --}} @error('password')
{{ $message }}
@enderror
``` ### Explanation of the Code 1. **`old('field_name')`**: We use the `old()` helper to repopulate the input fields with the data the user previously entered when the validation failed. This prevents the user from having to retype everything. 2. **`@error('field_name')`**: This is the crucial Blade directive. It checks if an error exists on the model/request for the specified field name (e.g., `'name'`). If an error exists, it executes the code block inside. 3. **`{{ $message }}`**: Inside the `@error` block, `$message` holds the specific validation message you defined in your controller or request. This pattern ensures that errors are displayed contextually right next to the field they relate to, providing immediate and actionable feedback to the user. This level of detail is vital when building robust applications using Laravel’s powerful validation system. ## Defining Custom Error Messages The second part of your question concerns where to define these custom messages. In a well-structured Laravel application, error messages should be defined where the validation logic resides—typically in your Controller or, preferably, within a dedicated Form Request class. This separation of concerns is a core principle of clean development practices advocated by the Laravel framework. ### Defining Messages in the Controller/Request When you define validation rules using methods like `validate()` on a Request object or Eloquent model, you can provide custom messages directly within that definition: **Example using a Form Request:** ```php // app/Http/Requests/StorePostRequest.php public function rules() { return [ 'name' => 'required|string|max:255', 'email' => 'required|email|unique:users', 'password' => 'required|min:8', ]; } ``` And to define custom messages for these rules, you would typically use a custom message file or the