我通过使用Polymorphic关系修复它。这不是最优的,因为使用我想要在关系上设置的属性来创建额外的节点,但它现在起作用。这里是关系类,我创建:
class Relation extends NeoEloquent
{
protected $label = 'Relation';
protected $guarded = [];
public $timestamps = false;
protected $fillable = ['relation_name','relation_description'];
public function subject()
{
return $this->morphMany('App\Term','TO');
}
}
这里是期限类:
class Term extends NeoEloquent
{
protected $label = 'Term';
protected $guarded = [];
public $timestamps = false;
protected $fillable = ['term_name','term_definition'];
public function author()
{
return $this->belongsTo('App\User', 'CREATED');
}
public function relationship($morph=null)
{
return $this->hyperMorph($morph, 'App\Relation', 'RELATION', 'TO');
}
public function object()
{
return $this->belongsToMany('App\Term', 'RELATION');
}
public function whichRelation()
{
return $this->morphMany('App\Relation','TO');
}
}
我开源一些地方为Laravel + NeoEloquent + Neo4j的演示。链接到github在这里:https://github.com/pietheinstrengholt/laravel-neo4j-neoeloquent-demo