Comments (3)
So the starting point with this is to forget you're doing this for Laravel JSON:API, and instead think in terms of Eloquent.
How would you load this data in Eloquent? If you can write the Eloquent query that produces the result you want, then this package should be able to do it (and if it can't, then something is potentially missing). However, if you can't load it in Eloquent in the way that you want, that's going to make it exceptionally difficult for this package to do it. Not least because every relationship has to be supported for eager loading, so that we can avoid N+1 problems.
from laravel.
That's a good point @lindyhopchris
I would probably write something like
$client = Client::query()->with(['person.addresses'])->where('id', 1)->get()
and that would give something like
Client {
id: 1,
person_id: 1,
person: Person {
id: 1,
first_name: "Paul",
last_name: "Winston",
addresses: Collection {
all: [
Address: {
id: 1,
name: "home
},
Address: {
id: 2,
name: "work
}
]
}
}
}
So, yeah, it's not in the format I want it.
I'm now thinking that maybe I should have a api/v1/people
endpoint with a filter for clients, something like api/v1/people?filter[type][]=client
.
from laravel.
I have ended up creating a non-eloquent resource as explained in the documentation, where the repository class you need to create actually uses the Eloquent query builder.
from laravel.
Related Issues (20)
- 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
- [question] Validation on filter values HOT 4
- route model binding (Variable name cannot be longer than 32 characters in route pattern) HOT 9
- How to create resource belongsTo resource in one request? HOT 3
- Controllers cannot be placed in a custom namespace HOT 5
- Rules in a a ResourceRequest are not checked against the Schema's defined fields; no exception thrown for an incorrect Request HOT 2
- [Feature Request] Nesting Filters HOT 1
- Included morph to many data is `null` HOT 5
- Updating a model's relationships where the policy denies updating the relationship gives 200 OK, but doesn't update the relationship HOT 5
- Impossible to change route model binding? HOT 5
- Proper docs for v4.0 and Laravel 11.x HOT 1
- Exception Handling with Laravel 11.x HOT 8
- Filtering inlcuded resources 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.