<?php

namespace App\View\Composers;

use App\Models\Category;
use Illuminate\View\View;

class CategoryComposer
{
    public function compose(View $view)
    {
        $parent_categories = Category::whereNull('parent_id')->orderBy('name', 'ASC')->get();

        $top_parent_categories = clone $parent_categories->where('is_top', true);
        $non_top_parent_categories = clone $parent_categories->where('is_top', false);

        $view->with('parent_categories', $parent_categories)
            ->with('top_parent_categories', $top_parent_categories)
            ->with('non_top_parent_categories', $non_top_parent_categories);

    }
}
