node-categoires icon indicating copy to clipboard operation
node-categoires copied to clipboard

提两个trait NodeCategoryTrait的问题

Open charlesyq opened this issue 8 years ago • 2 comments

第一个: public function parent() { return $this->belongsTo(self::class, 'parent_id', 'id'); }
这里的self 应该不能这么用吧 应该改成static吧,不然指向的是NodeCategoryTrait本身,而不是model本身。 第二个: public function parents() { return $this->where(DB::raw("LOCATE(node, '{$this->node}')"), '>', 0) ->where('id', '<>', $this->id)->get(); } 这个的实现方式没有必要吧 public function parents() { $node_array = explode(',',$this->node); return $this->whereIn("id",$node_array)->where('id', '<>', $this->id)->get(); } 讲道理这样的效率会高很多吧。

charlesyq avatar May 12 '16 02:05 charlesyq