laravel-medialibrary icon indicating copy to clipboard operation
laravel-medialibrary copied to clipboard

Add support for callables in hasMedia() filters

Open crossiatlas opened this issue 6 months ago • 2 comments

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. 2024-08-20_11-26

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 both array and callable filters, as per getMedia()
  • 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!)

crossiatlas avatar Aug 20 '24 02:08 crossiatlas