2017 © Pedro PelĂĄez
 

package shield

A simple way to centralize your validation rules for laravel

image

artesaos/shield

A simple way to centralize your validation rules for laravel

  • Wednesday, August 24, 2016
  • by vinicius73
  • Repository
  • 9 Watchers
  • 30 Stars
  • 560 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 10 Versions
  • 7 % Grown

The README.md

Artesaos - Shield

ArtesĂŁos Shield provides you a simple way to centralize your validation rules. It was mainly designed to solve the FormRequest rules practice, that is valid outside HTTP requests., (*1)

Installing

The package installation can be done with composer by the following command:, (*2)

composer require artesaos/shield

Shield does not provides Facades or ServiceProviders, they aren't needed., (*3)

Usage

1 - Defining Rules

Operating Shield is simple. It starts by defining a rules class for your model or other kind of entity. Take a look on the following example:, (*4)

<?php

namespace App\Domains\Users\Rules;

use Artesaos\Shield\Rules

class UserRules extends Rules
{
    public function defaultRules()
    {
        return [
            'name' => 'required|min:6',
        ];
    }

    public function creating($callback=null)
    {
        // returnRules method should be used
        // whenever the rules should be merged
        // with the default ones.
        return $this->returnRules([
            'email' => 'required|email',
        ], $callback);
    }

    // any other methods / actions that needs rules

}

2 - Enabling Rules

You could instantiate the rules by hand, but the recommended way of doing it is setting a static property into the class that owns the rules and using the proper trait, (*5)

<?php

// some other use statements here
use Artesaos\Shield\HasRules;
use App\Domains\Users\Rules\UserRules;

class User extends Model
{
    // using the rules trait
    use HasRules;

    // setting the rules class
    protected static $rulesFrom = UserRules::class

    // some model stuff here
}

3 - Usage

Whenever you need to access the rules, you can do it by creating a new instance of the rules class, or just using the classes (mainly models) you enabled., (*6)

User::rules()->creating();

User::rules()->updating();

User::rules()->yourCustomMethodForACustomAction();

User::rules()->whatever();

A really nice way of using it inside FormRequests are by passing the current HTTP method, that will be translated to the corresponding rules method (that's a convention), (*7)


// inside a form request User::rules()->byRequestType($this->getMethod()); // wherever you have a request instance User::rules()->byRequestType($request->getMethod());

Credits

The Versions

24/08 2016

dev-develop

dev-develop https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

by Diego Hernandes
by Vinicius Reis

laravel validation modules rules ddd form request

24/08 2016

dev-master

9999999-dev https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

by Diego Hernandes
by Vinicius Reis

laravel validation modules rules ddd form request

24/08 2016

2.0.0

2.0.0.0 https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

by Diego Hernandes
by Vinicius Reis

laravel validation modules rules ddd form request

02/07 2016

v1.0.2

1.0.2.0 https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

by Vinicius Reis

laravel validation modules rules ddd form request

02/07 2016

v1.0.1

1.0.1.0 https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

by Vinicius Reis

laravel validation modules rules ddd form request

02/07 2016

v1.0.0

1.0.0.0 https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

by Vinicius Reis

laravel validation modules rules ddd form request

23/05 2016

v0.5.2

0.5.2.0 https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius Reis

laravel validation modules rules ddd form request

23/05 2016

dev-analysis-XVBD0P

dev-analysis-XVBD0P https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius Reis

laravel validation modules rules ddd form request

22/05 2016

v0.5.1

0.5.1.0 https://github.com/artesaos/shield

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius Reis

laravel validation modules rules ddd form request

22/05 2016

v0.5.0

0.5.0.0

A simple way to centralize your validation rules for laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius Reis