Skip to content

Appending attributes based on scope #473

Answered by AlexVanderbist
chelout asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! I'm not sure we can easily achieve something like this using just appended attributes in this package. The query builder actually only builds queries, allowing appended attributes to be added using this package might've been a mistake 😅

Probably not the answer you were looking for but I'd suggest using Laravel's API resources to achieve this: https://laravel.com/docs/master/eloquent-resources. Using a resource you can conditionally add a couple of statistics fields whenever the fields are loaded in the query. This will probably cleanup your code quite a bit as well.

Good luck!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AlexVanderbist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #473 on June 17, 2020 07:54.