src/Mediable.php
public function getMediaMatchAll(array $tags)
    {
        $this->rehydrateMediaIfNecessary($tags);

        //group all tags for each media
        $model_tags = $this->media->reduce(function ($carry, Media $media) {
            $carry[$media->getKey()][] = $media->pivot->tag;

            return $carry;
        }, []);

        //exclude media not matching all tags
        return $this->media->filter(function (Media $media) use ($tags, $model_tags) {
            return count(array_intersect($tags, $model_tags[$media->getKey()])) === count($tags);
        })
        //remove duplicate media
        ->keyBy(function (Media $media) {
            return $media->getKey();
        })->values();
    }
public function getMediaMatchAll(array $tags)
    {
        $this->rehydrateMediaIfNecessary($tags);

        //group all tags for each media
        $model_tags = $this->media->reduce(function ($carry, Media $media) {
            $carry[$media->getKey()][] = $media->pivot->tag;

            return $carry;
        }, []);

        //exclude media not matching all tags
        return $this->media->filter(function (Media $media) use ($tags, $model_tags) {
            return count(array_intersect($tags, $model_tags[$media->getKey()])) === count($tags);
        })
        //remove duplicate media
        ->keyBy(function (Media $media) {
            return $media->getKey();
        })->values();
    }
public function getMediaMatchAll ( array $ tags ) { $ this -> rehydrateMediaIfNecessary ( $ tags ) ; //group all tags for each media $ model_tags = $ this -> media -> reduce ( function ( $ carry , Media $ media ) { $ carry [ $ media -> getKey ( ) ] [ ] = $ media -> pivot -> tag ; return $ carry ; } , [ ] ) ; //exclude media not matching all tags return $ this -> media -> filter ( function ( Media $ media ) use ( $ tags , $ model_tags ) { return count ( array_intersect ( $ tags , $ model_tags [ $ media -> getKey ( ) ] ) ) === count ( $ tags ) ; } ) //remove duplicate media -> keyBy ( function ( Media $ media ) { return $ media -> getKey ( ) ; } ) -> values ( ) ; }
Retrieve media attached to multiple tags simultaneously.
@param string[] $tags
@return \Illuminate\Database\Eloquent\Collection|\Plank\Mediable\Media[]
Retrieve media attached to multiple tags simultaneously .