Comments (3)
@paul-thebaud thanks for raising this issue, sorry I've only just seen it. (Must have missed the notification.)
I'm slightly unclear on the use case here, so if you could provide an example of what you're trying to do, that would help.
At the moment I would say it's not worth you submitting a PR. I've got quite a lot of major changes made ready for the v4 release. So I think the way forward is for me to understand your use case better, then I can see whether it needs to go into the current version or v4.
from laravel.
Hi @lindyhopchris, here is a simple (and dummy) example:
Let's take an API with two resources: applications and services. An application has many services. Users can attach services to their application, but only if they have access to these services.
I want to let users update their applications using a PUT request to /api/v1/applications/<ID>
, and change the services inside this request. Service availability is check through a Laravel policy ServicePolicy
. This is why I need to validate the relation values (eloquent instances) and not only the given Types/IDs.
I hope this will help.
from laravel.
@paul-thebaud sorry, just circling back to this.
The way to solve this is to write a Laravel validation rule: https://laravel.com/docs/10.x/validation#custom-validation-rules
And attach it to the services
value. That will be an array of all the type
and id
combinations in the services array. The validation rule should then do a database query (or whatever else it is you do) to check whether those ids are ones the user has access to.
If you can't check that without loading the service models, your rule can pull all of those models out of the database using the whereKey()
Eloquent query builder method, which is allowed to take an array of ids. Then iterate over them and check each one.
from laravel.
Related Issues (20)
- Mark routes in router as JSON API routes HOT 7
- How do you filter for date range? HOT 6
- Show or ignore attributes in resource HOT 1
- Hiding field using helper method like isViewingOne HOT 1
- Missing relationships for included resource
- [Question] How to include nested polymorphic relationships HOT 3
- Question: how do I create a simple endpoint /login? HOT 3
- Feature test on view single resource HOT 1
- How do I create a custom attribute in a schema using the SUM function, or should I use a model accessor instead? HOT 3
- Location header missing on created resources without self link HOT 2
- Allow morph relationships to define conditional $with attributes HOT 3
- Question - Creating a Related Model and Establishing Relationship HOT 2
- Unable to encode compound document. See previous exception for cause of failure. HOT 7
- eager loading problem HOT 9
- Feature Requests: Inject Scopes middleware option HOT 5
- Best location to add cache for API get requests HOT 2
- Customize top-level meta when fetching related resource HOT 1
- Problem with countables relationships HOT 15
- Incorrect data serialization within ArrayHash (Hashable trait) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel.