Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMedia('') returns all media, is this intended behaviour? #1697

Closed
ju5t opened this issue Jan 14, 2020 · 3 comments
Closed

getMedia('') returns all media, is this intended behaviour? #1697

ju5t opened this issue Jan 14, 2020 · 3 comments

Comments

@ju5t
Copy link

ju5t commented Jan 14, 2020

I know we can use $item->media to get all media for a selected item, but I prefer the same output as getMedia(). As it turns out, you can run getMedia('') and pass an empty $collectionName as argument. This will load all media with loadMedia() and supports empty strings.

https://github.com/spatie/laravel-medialibrary/blob/9fa2989f826da065d098f6f865cc7ad755c35d33/src/HasMedia/HasMediaTrait.php#L505-#L521

This seems to be expected / intended behaviour. I didn't expect this to be honest. I know it's hard to predict the future but can I expect this to stay like this or did I wake a sleeping dog?

Thanks for all the hard work by the way. It's very much appreciated!

@freekmurze
Copy link
Member

It's a fair remark, I agree that it's a little bit inconsistent now. Changing this will be a breaking change. I'll fix this in a new major release.

@freekmurze
Copy link
Member

This has been implemented on the v8 branch.

@aliwesome
Copy link

Isn't it a good idea that we could have multiple arguments as $collectionNames for input?

// same behavior 
$item->getMedia($collectionName);

// expected behavior for multiple collections
$item->getMeida($collectionNames);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants