2017 © Pedro Peláez
 

library ease-request

A laravel package to ease Input validation

image

tkeer/ease-request

A laravel package to ease Input validation

  • Monday, July 24, 2017
  • by tkeer
  • Repository
  • 2 Watchers
  • 3 Stars
  • 148 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

How it works

Inside the rules function of FormRequest class, write rule like this, (*1)

name => exists:users,name,group_id,{group_id}, (*2)

Whenever you will place any keyword inside curly braces EaseRequest will replace those keyword with values fetched from Request or your custom function, (*3)

If group_id is 3 in Request, above rule will be converted to following, (*4)

name => exists:users,name,group_id,3, (*5)

About EaseRequest

EaseRequest is laravel package that supports updating FormRequest validation rules at the run time., (*6)

Example

Let suppose you want to update a student data, student have class_id and school_id. You want to update student's class and you want to validate that class exists in the database. With current laravel implementation, it will work fine. Here is the rule.., (*7)

class_id => exists:classes,class_id

What if you want also to verify that the class also belongs to the student's school. Laravel gives you the option for adding the where conditions to the rule., (*8)

class_id => exists:classes,class_id,NULL,id,school_id,1

But you have to provide hard coded value for where conditions., (*9)

Using this package you can update your rules at run time. You can add your keyword in culry braces and this package will fetch the values from the Request and update the rule., (*10)

class_id => exists:classes,class_id,NULL,id,school_id,{school_id}

You can also define a method to be called for updating the rules instead of fetching value from Request class. Just write the method in your class with same name of the keyword written in curly braces. This way your method will called and returned value from your method will be added at the place of the keyword., (*11)

private function school_id()
{
        return (int)\Request::get('school_id');
}

Installation

composer require tkeer/ease-request 1.*, (*12)

Usage

Using abstract class EaseRequest

Extend your class by EaseRequest instead of FormRequest, implement abstract function preRules in your class and define all your rules in that function., (*13)

Using trait EaseRequestTrait

Extend your class by FormRequest and add EaseRequestTrait in the class. Define preRules function in you class and add all your rules in that function., (*14)

The Versions

24/07 2017

dev-master

9999999-dev

A laravel package to ease Input validation

  Sources   Download

MIT

The Requires

 

by taukeer

laravel validation dynamic rules

23/07 2017

v1.0.2

1.0.2.0

A laravel package to ease Input validation

  Sources   Download

MIT

The Requires

 

by taukeer

laravel validation dynamic rules

23/07 2017

1.0.1

1.0.1.0

An laravel package to ease Input validation

  Sources   Download

MIT

by taukeer

23/07 2017

1.0

1.0.0.0

An laravel package to ease Input validation

  Sources   Download

MIT

by taukeer