public function sortByKeys($links, $keys)
    {
        if (! is_null($keys)) {
            $links = $links->keyBy('id');

            $sortedLinks = [];
            foreach ($keys as $key) {
                $sortedLinks[] = $links[$key];
            }

            return collect($sortedLinks);
        }

        return $links;
    }
public function sortByKeys($links, $keys)
    {
        if (! is_null($keys)) {
            $links = $links->keyBy('id');

            $sortedLinks = [];
            foreach ($keys as $key) {
                $sortedLinks[] = $links[$key];
            }

            return collect($sortedLinks);
        }

        return $links;
    }
public function sortByKeys ( $ links , $ keys ) { if ( ! is_null ( $ keys ) ) { $ links = $ links -> keyBy ( 'id' ) ; $ sortedLinks = [ ] ; foreach ( $ keys as $ key ) { $ sortedLinks [ ] = $ links [ $ key ] ; } return collect ( $ sortedLinks ) ; } return $ links ; }
Sort by an existing set of keys

@param  collection $links
@param  array $keys

@return collection
Sort by an existing set of keys