GithubHelp home page GithubHelp logo

Comments (3)

lindyhopchris avatar lindyhopchris commented on July 17, 2024

@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.

paul-thebaud avatar paul-thebaud commented on July 17, 2024

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.

lindyhopchris avatar lindyhopchris commented on July 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.