laravel-json-api / eloquent

Serialize Eloquent models to JSON API resources
MIT License
12 stars 15 forks source link

Add support for custom too many relations #30

Closed genyded closed 10 months ago

genyded commented 10 months ago

We need support for custom relations like https://github.com/culturegr/custom-relation. However Laravel JSONAPI is restricted to the default types (HasMany, etc). This simple change allows our needed custom 'too many' relation to work in Laravel JSONAPI and does not seem to have any side effects. We hope it can be integrated or an alternative added so that we can continue using the library.

genyded commented 10 months ago

We're very grateful that we've been able to make Laravel JSONAPI meet our needs thus far and find it to be an awesome implementation! I also realize this is not the 'day' job. That said, I'll sleep better at night once this is tagged, as we are on a tight timeline.

lindyhopchris commented 10 months ago

No worries, just looking at it now!

lindyhopchris commented 10 months ago

@genyded quick question for you - how are you using this with the custom relation package? That package seems to be on Laravel 9, but this package is on Laravel 10?

lindyhopchris commented 10 months ago

Tagged as v3.1.0 which is for Laravel 10.

I'd prefer not to have to backport this to Laravel 9, but let me know how you're currently using the custom relations package.

genyded commented 10 months ago

No worries. We are not using that package but our own implementaion in 10. That was just an example to help explain.

On Sun, Oct 29, 2023, 9:00 AM Christopher Gammie @.***> wrote:

Tagged as v3.1.0 which is for Laravel 10.

I'd prefer not to have to backport this to Laravel 9, but let me know how you're currently using the custom relations package.

— Reply to this email directly, view it on GitHub https://github.com/laravel-json-api/eloquent/pull/30#issuecomment-1784122292, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXQLTCDMUXQTVLMLFMJCYTYBZHO3AVCNFSM6AAAAAA6PU5A7GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBUGEZDEMRZGI . You are receiving this because you were mentioned.Message ID: @.***>

lindyhopchris commented 10 months ago

Any plans to release your own implementation? I actually think it'd be really useful to link to from the Laravel JSON:API docs if you were going to open source it, as it would allow people to do more complex relations on their models, which they can then use for JSON:API.

genyded commented 10 months ago

Sorry, can't, it's for my day job. But it's pretty similar to any custom relation library out there. Just override the abstract methods on the base class with custom queries that return the desired results.

On Sun, Oct 29, 2023, 10:40 AM Christopher Gammie @.***> wrote:

Any plans to release your own implementation? I actually think it'd be really useful to link to from the Laravel JSON:API docs if you were going to open source it, as it would allow people to do more complex relations on their models, which they can then use for JSON:API.

— Reply to this email directly, view it on GitHub https://github.com/laravel-json-api/eloquent/pull/30#issuecomment-1784147386, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXQLTHUI4ORXBHXGRZFEMLYBZTHJAVCNFSM6AAAAAA6PU5A7GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBUGE2DOMZYGY . You are receiving this because you were mentioned.Message ID: @.***>