Skip to content

Commit cd2257c

Browse files
author
Sam Rapaport
committed
Remove dynamic method rules.
Intellegent rule selection is an interesting feature but is slow and only provides support for two RESTful methods. Adding additonal methods requires more conditionals and will cause performance to suffer as more are added. This commit removes this feature in favor for a more dynamic solution to come.
1 parent 566628d commit cd2257c

File tree

2 files changed

+0
-43
lines changed

2 files changed

+0
-43
lines changed

README.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -121,38 +121,6 @@ $validator = $validator->validate($request->all(), [
121121

122122
In this case, we are adding a rule for a `name` field, which will be merged with our rules defined in the `UserValidator`. By default, any rules passed explicitly to the `validate` method will override the rules defined in the validator if they exist.
123123

124-
### Additional Features
125-
---
126-
###### Dynamic Rules
127-
Since version 1.1, it is possible to have separate rules for updating and storing models, with the required `rules` property as a fallback. Simply define a `storing` and/or `updating` property on the validator in addition to the fallback `rules`, and Laravel Validation does the rest!
128-
129-
```
130-
class UserValidator extends Validator
131-
{
132-
/**
133-
* The validation rules.
134-
*
135-
* @var array
136-
*/
137-
protected $rules = [
138-
'password' => 'min:8|required',
139-
];
140-
141-
/**
142-
* Validation rules when updating a model.
143-
*
144-
* @var array
145-
*/
146-
protected $updating = [
147-
'password' => 'min:8',
148-
];
149-
}
150-
```
151-
152-
Upon validating, Laravel Validation checks if the controller method's name is a RESTful `update` or `store`. If it is one of these methods and its related `updating` or `storing` property exists, those rules will be used instead.
153-
154-
Note: The `rules` property is still **required** as a fallback. The `updating` and `storing` properties are always optional.
155-
156124
### Contributing
157125
---
158126
Contributions are more than welcome! You can submit feature requests to [rapaport.sam7@gmail.com](mailto:rapaport.sam7@gmail.com), or fork the repo yourself!

src/Validator.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@ public function getErrors()
4747
*/
4848
public function getRules()
4949
{
50-
$trace = debug_backtrace();
51-
$caller = $trace[1];
52-
53-
if ($caller['function'] == 'store' && property_exists($this, 'storing')) {
54-
return $this->storing;
55-
}
56-
57-
if ($caller['function'] == 'update' && property_exists($this, 'updating')) {
58-
return $this->updating;
59-
}
60-
6150
return $this->rules;
6251
}
6352

0 commit comments

Comments
 (0)