Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Behaviors Laravel Package

effiana/doctrine-behaviors

View on GitHub
Deep Wiki
Context7

Tree

Entity

<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TreeNodeInterface;
use Knp\DoctrineBehaviors\Model\Tree\TreeNodeTrait;

/**
 * [@ORM](https://github.com/ORM)\Entity
 */
class Category implements TreeNodeInterface
{
    use TreeNodeTrait;

    /**
     * [@ORM](https://github.com/ORM)\Column(type="string")
     * [@var](https://github.com/var) string
     */
    private $name;

    public function __toString() : string
    {
        return (string) $this->name;
    }
}

Usage

<?php

/** [@var](https://github.com/var) Knp\DoctrineBehaviors\Contract\Entity\TreeNodeInterface $category */
$category = new Category();
$category->setId(1);

$child = new Category();
$child->setId(2);

$child->setChildNodeOf($category);

$entityManager->persist($child);
$entityManager->persist($category);
$entityManager->flush();

$categoryRepository = $entityManager->getRepository(Category::class);

$root = $categoryRepository->getTree();

$root->getParentNode(); // null
$root->getChildNodes(); // ArrayCollection
$root[0][1]; // node or null
$root->isLeafNode(); // boolean
$root->isRootNode(); // boolean
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui