etrepat / Baum使用两张桌子

时间:2016-02-16 12:49:26

标签: php laravel nested-set-model

我试图将Baum用于两张桌子,但我无法实施。我的目的是有一个表来存储类别信息,如id,name,slug和status以及带有外键category_id的普通Baum表。在cadegoria,注册试图完成Tree :: create ([ 'name' => $ category-> name, 'category_id' => $ category-> category_id]);,但它不起作用。有人有提示吗?

Mmy模型文件是:

   namespace App;
use Illuminate\Database\Eloquent\Model;
use Baum\Node;

class Tree extends Node
{
    protected $table = 't_r_e_e_s';


    protected $parentColumn = 'id';

    protected $nameColumn = 'name';

    protected $parentId = 'parent_id';


    protected $leftColumn = 'lft';


    protected $rightColumn = 'rgt';


    protected $depthColumn = 'depth';

    protected $fk_category_id = 'category_id';


    protected $guarded = array('id', 'name', 'parent_id', 'lft', 'rgt', 'depth', 'category_id');



    public function category()
    {
        return $this->belongsToMany('App\Category', 'category_id');
    }
}

如果我评论受保护的属性有效。

0 个答案:

没有答案