node-categoires
node-categoires copied to clipboard
提两个trait NodeCategoryTrait的问题
第一个:
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(); }
讲道理这样的效率会高很多吧。