@extends('admin.layouts.app') @section('title', 'Categorii') @push('styles') @endpush @section('content')
{{-- Toast --}} @if(session('status'))
{{ session('status') }}
@endif @if($errors->any())
{{ $errors->first() }}
@endif {{-- Header --}}
Categorii

Administrare categorii

@php $mode = request('mode','table'); @endphp
Total: {{ $countAll }}
{{-- Search / Filters --}}
Reset
@if($mode === 'table') @php $parentId = (int) request('parent'); @endphp @if($parentId) @php // încercăm să luăm din $parents, altfel fallback DB (1 query) $ctx = $parents->firstWhere('id', $parentId) ?? \App\Models\Category::with('parent')->find($parentId); $crumb = []; $x = $ctx; while ($x) { $crumb[] = $x; $x = $x->parent; } $crumb = array_reverse($crumb); @endphp
⟵ Înapoi
@foreach($crumb as $i => $node) @if($i) @endif {{ $node->name }} @endforeach
@endif {{-- Table --}}
@forelse($categories as $c) @empty @endforelse
Categoria Slug Părinte Produse Activă Ordine Acțiuni
{{ $c->name }}
{{-- link rapid către subcategorii (dacă există) --}} @php // dacă ai withCount('children') în controller, preferă $c->children_count; $childrenCount = $c->children_count ?? $c->children()->count(); @endphp {{-- hint părinte (doar dacă nu ești deja în drill-down pe acel părinte) --}} @if(empty($parentId) && $c->parent)
Părinte: {{ $c->parent->name }}
@endif
/{{ $c->slug }} {{ $c->parent?->name ?? '—' }} {{ $c->products_count }}
@csrf
active ? 'checked' : '' }}>
@csrf
@csrf
#{{ $c->position }}
Nu există categorii.
Showing {{ $categories->firstItem() }} to {{ $categories->lastItem() }} of {{ $categories->total() }} results
{{ $categories->withQueryString()->onEachSide(1)->links('pagination::bootstrap-5') }}
@else {{-- ===== MOD ARBORE (nou) ===== --}} @php // Luăm toate categoriile o singură dată, ordonate; include și parent pt info $allCats = \App\Models\Category::with(['parent'])->withCount('products')->orderBy('position')->get(); // grupăm pe părinte $byParent = $allCats->groupBy(fn($c)=> (string)($c->parent_id ?? 'root')); $renderTree = function($nodes) use (&$renderTree, $byParent) { foreach ($nodes as $c) { $children = $byParent->get((string)$c->id) ?? collect(); $hasKids = $children->count() > 0; @endphp
  • @if($hasKids) @else @endif
    {{ $c->name }}
    /{{ $c->slug }}
    @if($c->parent)
    Părinte: {{ $c->parent->name }}
    @endif
    {{ $c->products_count }}
    @csrf
    active ? 'checked' : '' }}>
    #{{ $c->position }}
    @csrf
    @csrf
    @csrf @method('DELETE')
    @if($hasKids)
      @php $renderTree($children); @endphp
    @endif
  • @php } }; $roots = $byParent->get('root') ?? collect(); @endphp
      @php $renderTree($roots); @endphp
    {{-- în modul Arbore nu are sens paginația; filtrarea se face live din căsuța de căutare --}} @endif
    {{-- MODAL: ADD --}} {{-- MODAL: EDIT --}} {{-- MODAL: DELETE --}} @endsection @push('styles') @endpush @push('scripts') @endpush