Replies: 3 comments 1 reply
-
It's cool 👌 |
Beta Was this translation helpful? Give feedback.
-
Could have used this in the past too - especially because of soft-deleted. You could create a new Would be very easy to distinguish with named parameters: Rule::exists(Project::class, 'id', scopes: true), |
Beta Was this translation helpful? Give feedback.
-
I think that Validator is a macroable class, so in case the idea is no accepted, you could add your own ‘existsInCurrentTenant’ rule |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be very cool to have an option, to make the validation rule "exists" use the eloquent query builder, instead of the db query builder. This way your global scopes would get applied.
In a very simple multi-tenancy implementation, imagine you have the following model:
Now if you try to validate a project_id, you always need to make sure to not forget the tenancy_id check:
This is pretty cumbersome and error-prone.
It would be super convenient to have an option to make the validation rule internally using the eloquent query builder, so that the global scopes get applied! Maybe this could be done if you specifically use the model namespace validation format:
But for sure it could also be done differently, if you do not want to introduce a breaking change here.
I would love to create a PR for this, if there is any chance it get merged?
Beta Was this translation helpful? Give feedback.
All reactions