Getting media urls just from builder query. #1981
Unanswered
finoghentov
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm creating API, is there any methods, how can I get all media urls for model just from builder.
![Снимок](https://user-images.githubusercontent.com/45954128/89798770-47a58180-db35-11ea-87aa-1eb70e1c7c40.PNG)
For Example:
App\AnyModel::get()->withMediaUrls(); // will return me collection with model and necessary media data such as url to default image and urls for media conversion
Something like at this image. Collection was mapped and generated new property in model for media, where Key is name of conversion and value is path to image.
Otherwise I need to make unnecessary cycles for formatting new array with that data. Or Maybe I have Model with relation in relation there, so I need to make more than one cycle for formatting this.
I created mixin for Collection Class, which mapping it and create readable data like at this screenshot.
Also I created method which maps all relations in model and all relations in relation and etc. while relations will end and return usefull data with images url.
It very usefull for making API.
It can be a little bit "expensive" for performance, if there are a lot of collections but I don't see another way to solve this problem.
Maybe I can make some test and add Pull Request for adding this ability for this library?
Beta Was this translation helpful? Give feedback.
All reactions