Laravel 5.6 $this->validate vs Validator::make()

Laravel 5.6 $this->validate vs Validator::make()

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

Stefan Bogdanescu

Founder & Senior Architect

Laravel 5.6 $this->validate vs Validator::make()

In Laravel 5.6, choosing between $this->validate() and Validator::make() often comes down to your routing strategy and how you intend to handle validation failures. While both methods ultimately utilize the same underlying Illuminate\Validation\Validator class, they trigger different HTTP behaviors that dictate where they fit best in your architecture.

When working within a web application using server-side redirects, $this->validate() is the conventional choice. This method is designed to work seamlessly with Laravel's session-based redirect helpers. If the validator fails, it automatically generates a redirect_back() response and flashes the error messages into the session. This allows you to bypass the explicit validation logic in your controller method and let the framework handle the return path for you.

public function store(Request $request)
{
    // Automatically redirects back with errors if validation fails
    $this->validate($request, [
        'name' => 'required',
        'url' => 'required',
        'isPublic' => 'required'
    ]);

    Helpers::storeServer($request);

    return redirect('dashboard')->with('success', 'Server stored');
}

This approach is ideal for your web portion of the application because it keeps the controller logic clean. You don't need to manually check $validator->fails() or construct a return redirect() statement specifically for error cases. The framework handles the redirection and the flash message injection automatically, ensuring that the user lands on the page they just came from (or a defined fallback) with the validation errors readily available in the view.

However, API controllers operate on a completely different set of rules. An API should never redirect the client; it must return JSON responses regardless of success or failure. In an API context, using $this->validate() is problematic because it attempts to execute return redirect_back(). Since API clients do not follow redirects and expect structured data, this causes a mismatch in response expectations. Attempting to use $this->validate() in an API controller will result in an HTTP 302 redirect being sent back to the client instead of a JSON payload, breaking the contract of the API.

For your API classes, you must explicitly instantiate the validator using Validator::make(). This gives you full control over the response structure and status codes. You handle the failure logic manually, returning a 422 Unprocessable Entity status code along with the validation error messages in JSON format. This is the pattern you observed in your code snippet for the API store method.

public function store(Request $request)
{
    $validator = Validator::make($request->all(), [
        'name' => 'required',
        'url' => 'required',
        'isPublic' => 'required'
    ]);

    if ($validator->fails()) {
        return response()->json([
            'message' => $validator->messages()
        ], 422); // Standard status for validation errors
    }

    Helpers::storeServer($request);

    return response()->json(['message' => ['Server Stored']], 201);
}

There is a subtle technical distinction regarding the request data source as well. In web controllers using $this->validate(), Laravel automatically includes files uploaded via multipart/form-data in the validation array if they pass the initial check. With Validator::make() and $request->all(), you might need to be careful about how you access file uploads, though for standard fields like strings or booleans, the behavior is identical.

Your current separation of concerns—using Validator::make() for APIs and $this->validate() for web routes—is not just a proper way; it is the recommended best practice for Laravel 5.6. It aligns with the framework's intended workflow for each environment: leveraging session flashes and automatic redirects for the web interface, while maintaining strict JSON response contracts for API endpoints.

Our network