-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.6] Provide access to validated dataset #23385
Conversation
public function getDataForRules() | ||
{ | ||
$ruleKeys = collect($this->getRules())->keys()->map(function ($rule) { | ||
return str_contains($rule, '.') ? explode('.', $rule)[0] : $rule; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small optimization, but I suspect the following is faster and does the same:
return explode('.', $rule, 2)[0];
The str_contains is not necessary, and the limit arg to explode will increase performance by early termination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great -- I actually copied that line from Foundation/Providers/FoundationServiceProvider.php so the optimization can be made there as well.
Is there any way this can go into 5.6? I really need this in a project I'm working on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please target the 5.6 branch. I marked it as 5.7 because you targetted master. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I've rebased off the 5.6 branch and implemented your change. Are unit tests needed or is the PR good as-is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests would be great please. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added tests. Anything else I can do to get this merged faster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TravisCI appears to be failing due to another commit that is already on 5.6
Cannot redeclare Illuminate\Tests\Database\DatabaseQueryBuilderTest::testWhereTimePostgres
Can't the |
@deleugpn Currently validate() does not return anything -- are you saying we should have it return the validated data from my new function?
That would probably be preferable, but I didn't want to delay this PR if that was going to be a controversial change. If it's not controversial I can delete my getDataValidated() method and instead just have the validate() method return $this->getDataForRules(); |
I guess that would be a breaking change, yes. So maybe you can open a separate PR to change that tagging 5.7 while keeping this one as-is tagging 5.6 |
Probably validated could return the data being validated similar to |
@taylorotwell Thanks Taylor -- I've updated the code and created a new PR to add a return value for validate() so that it mimics |
Currently in your controller if you're using:
$data = $request->validate([...]);
If you need to switch to using advanced rules, there is no firect method available for accessing the validated data: