我正在尝试将 Baum 与两个表一起使用,但我无法实现。我的意图是有一个表来存储类别信息作为 id、名称、slug 和状态以及具有外键 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');
}
}
如果我评论受保护的属性有效。