src/Mediable.php
private function getOrderValueForTags($tags)
    {
        $q = $this->media()->newPivotStatement();
        $tags = array_map('strval', (array) $tags);
        $grammar = $q->getGrammar();

        $result = $q->selectRaw($grammar->wrap('tag').', max('.$grammar->wrap('order').') as aggregate')
            ->where('mediable_type', $this->getMorphClass())
            ->where('mediable_id', $this->getKey())
            ->whereIn('tag', $tags)
            ->groupBy('tag')
            ->pluck('aggregate', 'tag');

        $empty = array_combine($tags, array_fill(0, count($tags), 0));

        $merged = collect($result)->toArray() + $empty;
        return $merged;
    }
private function getOrderValueForTags($tags)
    {
        $q = $this->media()->newPivotStatement();
        $tags = array_map('strval', (array) $tags);
        $grammar = $q->getGrammar();

        $result = $q->selectRaw($grammar->wrap('tag').', max('.$grammar->wrap('order').') as aggregate')
            ->where('mediable_type', $this->getMorphClass())
            ->where('mediable_id', $this->getKey())
            ->whereIn('tag', $tags)
            ->groupBy('tag')
            ->pluck('aggregate', 'tag');

        $empty = array_combine($tags, array_fill(0, count($tags), 0));

        $merged = collect($result)->toArray() + $empty;
        return $merged;
    }
private function getOrderValueForTags ( $ tags ) { $ q = $ this -> media ( ) -> newPivotStatement ( ) ; $ tags = array_map ( 'strval' , ( array ) $ tags ) ; $ grammar = $ q -> getGrammar ( ) ; $ result = $ q -> selectRaw ( $ grammar -> wrap ( 'tag' ) . ', max(' . $ grammar -> wrap ( 'order' ) . ') as aggregate' ) -> where ( 'mediable_type' , $ this -> getMorphClass ( ) ) -> where ( 'mediable_id' , $ this -> getKey ( ) ) -> whereIn ( 'tag' , $ tags ) -> groupBy ( 'tag' ) -> pluck ( 'aggregate' , 'tag' ) ; $ empty = array_combine ( $ tags , array_fill ( 0 , count ( $ tags ) , 0 ) ) ; $ merged = collect ( $ result ) -> toArray ( ) + $ empty ; return $ merged ; }
Determine the highest order value assigned to each provided tag.
@param  string|string[] $tags
@return array
Determine the highest order value assigned to each provided tag .