private function prepareRatios(Collection $categories)
    {
        $ratios = $categories->filter(function (Category $category) {
                return $category->hasPosts();
            })
            ->transform(function (Category $category) {
                return [
                    'label' => $category->name,
                    'posts' => $category->posts->count(),
                ];
            })
            ->sortByDesc('posts');

        $chunk  = $ratios->splice(5);
        $ratios = $this->colorizeRatios($ratios);

        return $chunk->isEmpty() ? $ratios : $ratios->push([
            'label' => 'Other Categories',
            'posts' => $chunk->sum('posts'),
            'color' => '#D2D6DE',
        ]);
    }
private function prepareRatios(Collection $categories)
    {
        $ratios = $categories->filter(function (Category $category) {
                return $category->hasPosts();
            })
            ->transform(function (Category $category) {
                return [
                    'label' => $category->name,
                    'posts' => $category->posts->count(),
                ];
            })
            ->sortByDesc('posts');

        $chunk  = $ratios->splice(5);
        $ratios = $this->colorizeRatios($ratios);

        return $chunk->isEmpty() ? $ratios : $ratios->push([
            'label' => 'Other Categories',
            'posts' => $chunk->sum('posts'),
            'color' => '#D2D6DE',
        ]);
    }
private function prepareRatios ( Collection $ categories ) { $ ratios = $ categories -> filter ( function ( Category $ category ) { return $ category -> hasPosts ( ) ; } ) -> transform ( function ( Category $ category ) { return [ 'label' => $ category -> name , 'posts' => $ category -> posts -> count ( ) , ] ; } ) -> sortByDesc ( 'posts' ) ; $ chunk = $ ratios -> splice ( 5 ) ; $ ratios = $ this -> colorizeRatios ( $ ratios ) ; return $ chunk -> isEmpty ( ) ? $ ratios : $ ratios -> push ( [ 'label' => 'Other Categories' , 'posts' => $ chunk -> sum ( 'posts' ) , 'color' => '#D2D6DE' , ] ) ; }
Prepare the categories ratios.

@param  \Illuminate\Database\Eloquent\Collection  $categories

@return \Illuminate\Database\Eloquent\Collection
Prepare the categories ratios .