etrepat / baum

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.
http://etrepat.com/baum
MIT License
2.24k stars 459 forks source link

getNestedList and JSON column #275

Open ishosys opened 7 years ago

ishosys commented 7 years ago

Hi,

This function on JSON column thows an "array to string conversion error". Can you please fix it?

public static function getNestedList($column, $key = null, $seperator = ' ') {
    $instance = new static;
    $key = $key ?: $instance->getKeyName();
    $depthColumn = $instance->getDepthColumnName();
    $nodes = $instance->newNestedSetQuery()->get()->toArray();
    return array_combine(array_map(function($node) use($key) {
      return $node[$key];
    }, $nodes), array_map(function($node) use($seperator, $depthColumn, $column) {
      return str_repeat($seperator, $node[$depthColumn]) . $node[$column];
    }, $nodes));
  }