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

Access nested inputs with dot notation in find option of @can #1216 #1216

Merged
merged 7 commits into from
Mar 4, 2020
Merged

Access nested inputs with dot notation in find option of @can #1216 #1216

merged 7 commits into from
Mar 4, 2020

Conversation

andershagbard
Copy link
Contributor

@andershagbard andershagbard commented Mar 1, 2020

  • Added or updated tests
  • Added Docs for all relevant versions
  • Updated CHANGELOG.md

Resolves #1162

Changes
The find method of the can directive now uses Arr::get, to search the model. This allows to pass a string in a dot notation like data.foo.bar.

Breaking changes
Previously it would throw an Undefined Index Error if the string did not map to a value. Now it will throw a DefinitionException.

@spawnia
Copy link
Collaborator

spawnia commented Mar 2, 2020

This looks really clean, good work.

Previously it would throw an Undefined Index Error if the string did not map to a value. Now the value will be defaulted to null, and throw a ModelNotFoundException.

This kind of breakage is fine in a new minor version.

What do you think about adding an explicit exception for that case? It seems like it is distinct from not finding a model.

@andershagbard
Copy link
Contributor Author

What do you think about adding an explicit exception for that case? It seems like it is distinct from not finding a model.

Good idea. Just a generic server exception?

throw new \Exception("Undefined index. Could not find $find");

@spawnia
Copy link
Collaborator

spawnia commented Mar 2, 2020

I think that the onus is on the developer, they should just make the argument required.

We usually utilize the *Manipulator directive interfaces for this. They contain functions that are run during schema validation, so we could just throw a DefinitionException there to enforce the argument is defined as non-null !.

@andershagbard
Copy link
Contributor Author

Updated

@spawnia
Copy link
Collaborator

spawnia commented Mar 4, 2020

Nicely done, thank you

@spawnia spawnia changed the title Allow find argument to search nested data Access nested inputs with dot notation using the find option of @can Mar 4, 2020
@spawnia spawnia changed the title Access nested inputs with dot notation using the find option of @can Access nested inputs with dot notation in find option of @can #1216 Mar 4, 2020
@spawnia spawnia merged commit d1ae67b into nuwave:master Mar 4, 2020
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.

@can(find: String) can't access to nested values
2 participants