Git Product home page Git Product logo

laravel-ltree's Introduction

laravel-ltree

Github Status Coverage Status Latest Stable Version Total Downloads Code Intelligence Status Build Status Code Coverage Scrutinizer Code Quality

LTree Extension (PostgreSQL) for Laravel.

Installation

Run this command to install:

php composer.phar require umbrellio/laravel-ltree

How to use

Implement your Eloquent\Model from LTreeModelInterface and use LTreeModelTrait.

Use LTreeService for build path:

  1. when create model: createPath(LTreeModelInterface $model)
  2. when update model: updatePath(LTreeModelInterface $model) for update path for model and children
  3. when delete model: dropDescendants(LTreeModelInterface $model) for delete children models

The get() method returns LTreeCollection, instead of the usual Eloquent\Collection.

LTreeCollection has a toTree() method that converts a flat collection to a tree.

LTreeResourceCollection & LTreeResource, which take LTreeCollection as an argument, will also be useful.

Authors

Created by Korben Dallas.

Supported by Umbrellio

laravel-ltree's People

Contributors

art4es avatar cugrif avatar dependabot-preview[bot] avatar dependabot[bot] avatar jamesrusso avatar pvsaintpe avatar zlob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

laravel-ltree's Issues

Невозможно взять дерево не с корневого элемента.

Есть функция построения дерева (модель User) дерево строится от самого пользователя "вниз".
static function getList()
{
return new UserResourceCollection(self::whereRaw("path <@ text2ltree(''1.12.14'') and nLevel(path) <= 10 order by id")
->get(), null, true, false);
}

при запросе к данной функции вылетает ошибка:
"Umbrellio\LTree\Exceptions\LTreeUndefinedNodeException
There is no node with id '12'"
Если убрать " null, true, false", после get(), то все отрабатывает, но выдает все дерево вверх, что не нужно.

Screenshot_1
Screenshot_2
Screenshot_14

static function getList()
{
return new UserResourceCollection(self::whereRaw("path <@ text2ltree('1.12.14') and nLevel(path) <= 10 order by id")
->get());//, null, true, false);

Screenshot_3
}

Расширение описания

Огромное спасибо автору, расширение отличное, но информации для интеграции в свой проект в описании, на мой взгляд, очень мало. Только благодаря персональной консультации я смог его интегрировать. Информации в интернете по данному вопросу я нашел только одну статью, перепечатанную несколько раз, причем рекомендации статьи и те действия, которые я сделал после консультации с автором, очень сильно отличаются. Я думаю, что с непониманием, как интегрировать это расширение сталкивался не только я. Поэтому предлагаю дать более полные, пошаговые инструкции для желающих использовать данное расширение.

Support UUID

Is your feature request related to a problem? Please describe.
UUID are not supported

Describe the solution you'd like
To Use uuid in an ltree a transform to replace "-" with "_" is needed, i think the interface could implement an overridable getKey or the helper could check (and clean) if the model is using a string type primary

Nullable support

Hello!

Can you, please, add nullable support in LtreeHelper (in wrapExpressions function)?
Like:

if ($value === null) {
    $expressions[] = sprintf('%s = %s', $column, 'null');
}

This is important for me and it's right logic if we want set some field to null after move node or other action with it.

Thx a lot!

Ошибка "There is no node with id" когда елемент есть в коллекции

Получаю такую ошибку, если не использовать сортировку

return new CommentResourceCollection($comments, null, false);

Хотя довольно легко можно исправить это поведение, если изначально создать все ноды, а затем только их использовать

foreach ($items as $item) {
    $node = new LTreeNode($item);

    $id = $item->{$this->idField};

    $this->nodes[$id] = $node;
}

foreach ($items as $item) {
    [$id, $parentId] = $this->getNodeIds($item);

    $node = $this->nodes[$id];

    $parentNode = $this->getNode($parentId);
    $parentNode->addChild($node);
}

Причем из-за того что все поля private, это создает очень большие проблемы при попытке что-то допилить самостоятельно. Почему не protected?

Laravel 10

Настало время сделать поддержку Laravel 10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.