laravel-medialibrary
laravel-medialibrary copied to clipboard
Add support for callables in hasMedia() filters
Description of Changes
I encountered a scenario where I expected $model->hasMedia('my-collection', $filters)
to accept a closure for $filters
, but it's typehinted to only support an array.
This PR updates the typehint to match getMedia()
In the meantime I worked around this via:
$model->getMedia('my-collection', fn (Media $media) => isset($media->custom_properties['something'])))->isNotEmpty()
Changes Made
- Update
hasMedia()
to support botharray
andcallable
filters, as pergetMedia()
- Update test coverage
Resolves #3526
(NOTE: This is my first contribution to this repository, I believe I've met the requirements but feel free to let me know if there's anything I'm missing and I'll update my PR. Thanks!)