Skip to content
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

[11.x] Add InteractsWithInput methods to ValidatedInput #51316

Merged
merged 28 commits into from
May 6, 2024

Conversation

aydinfatih
Copy link
Contributor

We cannot use integer, string, boolean, date etc methods via $request->safe().

When we want to use these methods via $request, it does not guarantee that the data is validated. With this PR, the following methods will be available based on validated data.

Also this PR will not cause a major change.

Example:

$request->safe()->filled('test');
$request->safe()->boolean('test');

Added

  • exists: Determine if the validated inputs contains a given input item key.
  • hasAny: Determine if the validated inputs contains any of the given inputs.
  • whenHas: Apply the callback if the validated inputs contains the given input item key.
  • filled: Determine if the validated inputs contains a non-empty value for an input item.
  • isNotFilled: Determine if the validated inputs contains an empty value for an input item.
  • anyFilled: Determine if the validated inputs contains a non-empty value for any of the given inputs.
  • whenFilled: Apply the callback if the validated inputs contains a non-empty value for the given input item key.
  • whenMissing: Apply the callback if the validated inputs is missing the given input item key.
  • keys: Get the keys for all of the validated input.
  • input: Retrieve an input item from the validated inputs.
  • str: Retrieve input from the validated inputs as a Stringable instance.
  • string: Retrieve input from the validated inputs as a Stringable instance.
  • boolean: Retrieve input as a boolean value.
  • integer: Retrieve input as an integer value.
  • float: Retrieve input as a float value.
  • date: Retrieve input from the validated inputs as a Carbon instance.
  • enum: Retrieve input from the validated inputs as an enum.
  • dd: Dump the validated inputs items and end the script.
  • dump: Dump the items.

Changed

  • Add $key prop to collect method in ValidatedInput

@taylorotwell taylorotwell merged commit 451247f into laravel:11.x May 6, 2024
28 checks passed
@NickSdot
Copy link
Contributor

NickSdot commented May 7, 2024

@taylorotwell I know the author of #51302 still has the PR in draft. But since this here got merged it's perhaps worth to have a look before release?

Would a centralised api make sense?

@bert-w anything missing to get your PR out of draft to be reviewed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants