Merhaba, herkese iyi günler dilerim. Forumlardan araştırarak elde ettiğim bir kategori sistemi bulunmakta. Yalnız bu kategori sistemi yaklaşık 520 adet veritabanı sorgusu yapmakta. Bu sorunu sizce nasıl çözebilirim? Kodlar;
Model;
protected $appends = [        'getParentsTree',    ];     public function children()    {        return $this->hasMany(Category::class, 'parent_id')->orderBy('id', 'ASC');    }    public static function getParentsTree($category, $title)    {        if ($category->parent_id == 0) {            return $title;        }        $parent = Category::findOrFail($category->parent_id);        $title = $parent->title . ' > ' . $title;         return Category::getParentsTree($parent, $title);    }
View’e aktarım;
view()->share('categorys', Category::where('parent_id', 0)->with('children')->orderBy('id', 'ASC')->get());
View;
@foreach ($categorys as $category)    @if (count($category->children))    <li>        <ul class="dropdown-c">            <li>                <a class="cwCategoryFontSize85" href="{{ route('Web.category.products', $category->slug) }}">{{ $category->title }}</a>                <ul>                    @include('Web.Category.category', ['children'=>$category->children])                </ul>            </li>        </ul>        @else        <ul class="dropdown-c">            <li>                <a class="cwCategoryFontSize85" href="{{ route('Web.category.products', $category->slug) }}">{{ $category->title }}</a>            </li>        </ul>    @endif @endforeach
Web.Category.category;
@foreach ($children as $item)        @if (count($item->children))            <li>                <a href="{{ route('Web.category.products', $item->slug) }}">{{ $item->title }} <i class="fi-rs-angle-right"></i></a>                <ul class="level-menu level-menu-modify">                    @include('Web.Category.category', ['children'=>$item->children])                </ul>            </li>        @else            <li><a href="{{ route('Web.category.products', $item->slug) }}">{{ $item->title }}</a></li>        @endif @endforeach
Kodları doğru bir şekilde yerleştiremedim özür dilerim. Yardım eden herkese şimdiden çok teşekkür ederim