PHPackages                             okaybueno/validation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. okaybueno/validation

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

okaybueno/validation
====================

Validation as Service for Laravel applications.

v2.0.0(7y ago)04.8k[3 PRs](https://github.com/okaybueno/validation/pulls)2MITPHPPHP &gt;=7.1

Since Sep 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/okaybueno/validation)[ Packagist](https://packagist.org/packages/okaybueno/validation)[ RSS](/packages/okaybueno-validation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (7)Used By (2)

IMPORTANT ❗
===========

[](#important-)

**This package has been discontinued and it won't receive any other updates. If you're using it please consider migrating to another solution – or fork it and depend on your own version of package.**

---

ValidationService
=================

[](#validationservice)

A package that provides validation as a service for Laravel 5.x.

[![Latest Version on Packagist](https://camo.githubusercontent.com/5b0daf85e5ace82040801f750a63c67bdb9b03763a90ac827f231956d6f0ae8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6b61796275656e6f2f76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/okaybueno/validation)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/03037201c3f8d3e8ea4e2372c061ccbe59cb77031b3406ec18c2043f07dabab1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6f6b61796275656e6f2f76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/okaybueno/validation)[![Total Downloads](https://camo.githubusercontent.com/543321fec83a182b24503b386d642e25c79d8cd6f1f348d355c59d9478812e19/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6b61796275656e6f2f76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/okaybueno/validation)

Goal
----

[](#goal)

There is a lot of talk about where to perform the data validation: repositories? controllers? gateways? services? models? Each one has its point; good things and bad things... We personally found useful to extract this logic to a service that can be injected into other services on the same -or higher- layer.

So the goal of this package is to provide a simple validation service that can be injected into other services, and that although it uses the Laravel Validation class by default, it can be extended to use other validation libraries. This is a highly opinionated way of solving this issue.

Installation
------------

[](#installation)

1. Install this package by adding it to your `composer.json` or by running `composer require okaybueno/validation-service` in your project's folder.
2. Publish the configuration file by running `php artisan vendor:publish --provider="OkayBueno\Validation\ValidationServiceProvider"`.
3. Configure the `config/validators.php` file according to your needs, specifying the base namespace and directories for your validators.
4. Ready to go! No service provider or anything else needed :).

Usage
-----

[](#usage)

You just need to create a Validation interface with the different validation methods, and then create a new ´src´ directory where you will then create the validation class that extends the main validation class (`LaravelValidator`) and implements the previous interface. It sounds weird, huh? Lets see it with an example...

Examples
--------

[](#examples)

I personally like to split my Laravel code from my app code, so inside the app folder I usually create a folder that includes ALL the business logic that is lowly coupled to the framework: app/MyWebApp. Inside that folder I like to split my files into different folders, based on the role of these: Models? Repositories? Helpers? Services? Validators? And so on...

Once again -and this is a matter of taste, that's all- I like to split my services into areas of responsibility: Users, Auth, Mailing, etc. Therefore, I like to split my validators in different folders that then contain the different interfaces, along with the `src` folder that contains the implementation. So the folder structure inside my projects looks pretty much like this most of the times:

```
+-- app
|   +-- MyApp
|       +-- Models
|       +-- Helpers
|       +-- Repositories
|       .
|       .
|       +-- Validation
|           +-- Auth
|           +-- Mailing
|           +-- Users
|               +-- UserValidatorInterface.php
|               +-- src
                    +-- UsersValidator.php

```

Let's take a look at how I would implement the UserValidatorInterface and the UserValidator classes:

```
