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

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
Laravel 5.6 $this->validate vs Validator::make() - A Comprehensive Guide When working on a Laravel project, you might encounter two different ways to validate user input or data. These include using the $this->validate() method from within your controller class and utilizing the Validator::make() method outside of a class. In this blog post, we'll dive deeper into these two approaches in Laravel 5.6, explaining their differences, proper use cases, and when to apply each one. 1. Understanding $this->validate() and its usage: $this->validate() is a convenient method provided by Laravel to perform validation within the controller class. It's typically used in web-based applications where you want to ensure the user input adheres to predefined rules before proceeding with further actions, such as storing data to a database or performing additional logic. Here's an example of using $this->validate(): ```php public function store(Request $request) { $rules = [ 'name' => 'required', 'url' => 'required', 'isPublic' => 'required' ]; $validator = $this->validate($request, $rules); if ($validator) { Helpers::storeServer($request); return redirect('dashboard')->with('success', 'Server stored'); } else { return response()->json([ 'message' => ['Validation Failed'] ]); } } ``` 2. Explaining Validator::make() and its usage: Validator::make() is a more flexible approach for validation, allowing you to validate data outside of the controller class or within third-party packages that might not use Laravel's native conventions. This method can also be useful when validating data from multiple places in your application without duplicating implementation logic. Here's an example of using Validator::make(): ```php 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() ]); } else { Helpers::storeServer($request); return response()->json([ 'message' => [ 'Server Stored' ] ]); } } ``` 3. Comparison of both methods: In summary, $this->validate() is a convenient way to perform validation within the controller class for web-based applications when you want the user input to adhere to predefined rules. On the other hand, Validator::make() provides more flexibility and can be used outside of controllers or in third-party packages that might not follow Laravel's native conventions. It allows you to validate data from multiple places without duplicating implementation logic. 4. Conclusion: Ultimately, the choice between $this->validate() and Validator::make() largely depends on your project requirements and personal preferences. Both methods have their unique advantages, so it's essential to understand how and when to use each one. As always, it's vital to thoroughly test your application to ensure a smooth user experience while validating data effectively. For more in-depth discussions on Laravel and its features, visit https://laravelcompany.com for valuable resources and insights.