-
-
Notifications
You must be signed in to change notification settings - Fork 403
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
New Filter belongs to #975
Conversation
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.
Hi, thanks for the PR! Two small review comments, after that I'm happy to tweak the docs and merge this :)
return $relatedModel; | ||
} | ||
|
||
protected function getModelFromRelation(Model $model, string $relation, int $level = 0): ?Model |
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.
Is $level
still being used? I can see it's passed on recursively but never used.
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.
As a habit, whenever I make a recursive function I send the level parameter, sometimes it is necessary to determine the first iteration of the rest. In this case it was not necessary and I forgot to delete it. You can delete it safely.
{ | ||
public static function make($property): static | ||
{ | ||
return new static("Filter property `{$property}` is invalid."); |
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.
Can we add a $reason
to this exception? From the implementation I see there's only one reason this happens: belongs to relationship is not an Eloquent relationship
.
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.
Exactly.
There was another exception that I wasn't handling (on purpose), when the relation (or the last relation in a nested dotted string) is not a BelongTo relation, in that case an unhandled exception was thrown but Laravel gave a correct message and context to find this error. This case was not covered in the tests.
Based on that exception, now remove InvalidFilterProperty
and throw that same exception RelationNotFoundException
. I also added more test cases that cover all the options (this case and the previous one).
This native Laravel exception gives a more specific message to fix the error.
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.
@AlexVanderbist Have you been able to review this?
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.
@freekmurze Have you been able to review this?
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.
Perfect, thank you!
ff1034c
to
4b3f57e
Compare
Thanks @AlexVanderbist! The documentation is pending. |
This new filter receives the id and allows to call the native method
whereBelongsTo
method of the model (doc).The method accepts nested relationships.
The filter accepts receiving an array with the ids.
Unfortunately my English is not good and I couldn't write the documentation correctly.
If you think the PR is correct, could you help me with the documentation?