baum icon indicating copy to clipboard operation
baum copied to clipboard

Cannot use a string as custom key for eloquent model in v2.x-dev

Open chao opened this issue 6 years ago • 1 comments

It works just fine in version 1, but after I upgrade Laravel to 5.8 and Baum to v2.x-dev, I got a exception : Could not resolve target node. in Move.php L206.

Are we have to use integer as primary key in version 2?

chao avatar May 21 '19 09:05 chao

Well, I made some modifications for resolveNode function as following, it works well.

protected function resolveNode($node)
    {
        if (method_exists($node, 'refresh') && is_callable([$node, 'refresh'])) {
            return $node->refresh();
        }

        if ($node instanceof \Illuminate\Database\Eloquent\Model) {
            return $node->newQuery()->find($node->getKey());
        }

        if (!empty($node)) {
           return $this->node->newQuery()->find($node);
        }
        throw new MoveNotPossibleException('Could not resolve target node.');
    }

chao avatar May 21 '19 09:05 chao