Rest 使用lumen检索边和关系属性

Rest 使用lumen检索边和关系属性,rest,neo4j,lumen,neoeloquent,fastroute,Rest,Neo4j,Lumen,Neoeloquent,Fastroute,我是lumen和neo4j的新成员,我想为两个标签之间的特定关系添加一些属性 例如,如果我们假设展览标签和区域标签之间存在以坐标属性为特征的多对多关系,如何检索坐标属性 阅读NeoElount,我了解到,要检索两个标签之间的边,我必须遵循函数findZone中存在的程序: 编辑 正如用户Sven Hakvoort建议的那样,我需要更改 $this->belongsToMany('App\Zone', 'BELONGS_TO'); to $this->belongsToMany('Ap

我是lumen和neo4j的新成员,我想为两个标签之间的特定关系添加一些属性

例如,如果我们假设展览标签和区域标签之间存在以坐标属性为特征的多对多关系,如何检索坐标属性

阅读NeoElount,我了解到,要检索两个标签之间的边,我必须遵循函数findZone中存在的程序:

编辑 正如用户Sven Hakvoort建议的那样,我需要更改

$this->belongsToMany('App\Zone', 'BELONGS_TO'); to $this->belongsToMany('App\Zone', 'belongs_to');
现在,响应是500内部错误,堆栈跟踪:

    [2018-10-13 09:26:15] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to Vinelab\NeoEloquent\Eloquent\Edges\Finder::first() must be an instance of Vinelab\NeoEloquent\Eloquent\Model, null given, called in E:\laravel-projects\api_certose\vendor\vinelab\neoeloquent\src\Eloquent\Relations\BelongsToMany.php on line 158 in E:\laravel-projects\api_certose\vendor\vinelab\neoeloquent\src\Eloquent\Edges\Finder.php:70
Stack trace:
#0 E:\laravel-projects\api_certose\vendor\vinelab\neoeloquent\src\Eloquent\Relations\BelongsToMany.php(158): Vinelab\NeoEloquent\Eloquent\Edges\Finder->first(Object(App\Exhibit), NULL, 'belongs_to')
#1 E:\laravel-projects\api_certose\app\Exhibit.php(21): Vinelab\NeoEloquent\Eloquent\Relations\BelongsToMany->edge()
#2 E:\laravel-projects\api_certose\app\Http\Controllers\ExhibitController.php(44): App\Exhibit::findZone('159')
#3 [internal function]: App\Http\Controllers\ExhibitController->retrieveZone('159')
#4 E:\laravel-projects\api_certose\vendor\illuminate\container\BoundMethod.php(29): call_user_func_array(Array, Array)
#5 E:\laravel-projects\api_certose\vendor\illuminate\container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#6 E:\laravel-projects\api_certose\vendor\illuminate\container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#7 E:\laravel-projects\api_certose\vendor\illuminate\container\Container.php(564): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#8 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(373): Illuminate\Container\Container->call(Array, Array)
#9 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(339): Laravel\Lumen\Application->callControllerCallable(Array, Array)
#10 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(313): Laravel\Lumen\Application->callLumenController(Object(App\Http\Controllers\ExhibitController), 'retrieveZone', Array)
#11 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(275): Laravel\Lumen\Application->callControllerAction(Array)
#12 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(260): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array)
#13 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(230): Laravel\Lumen\Application->handleFoundRoute(Array)
#14 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(164): Laravel\Lumen\Application->handleDispatcherResponse(Array)
#15 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(413): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}()
#16 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(166): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#17 E:\laravel-projects\api_certose\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(107): Laravel\Lumen\Application->dispatch(NULL)
#18 E:\laravel-projects\api_certose\public\index.php(28): Laravel\Lumen\Application->run()
#19 {main} {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 2 passed to Vinelab\\NeoEloquent\\Eloquent\\Edges\\Finder::first() must be an instance of Vinelab\\NeoEloquent\\Eloquent\\Model, null given, called in E:\\laravel-projects\\api_certose\\vendor\\vinelab\
eoeloquent\\src\\Eloquent\\Relations\\BelongsToMany.php on line 158 at E:\\laravel-projects\\api_certose\\vendor\\vinelab\
eoeloquent\\src\\Eloquent\\Edges\\Finder.php:70)
[stacktrace]
#0 E:\\laravel-projects\\api_certose\\vendor\\vinelab\
eoeloquent\\src\\Eloquent\\Relations\\BelongsToMany.php(158): Vinelab\\NeoEloquent\\Eloquent\\Edges\\Finder->first(Object(App\\Exhibit), NULL, 'belongs_to')
#1 E:\\laravel-projects\\api_certose\\app\\Exhibit.php(21): Vinelab\\NeoEloquent\\Eloquent\\Relations\\BelongsToMany->edge()
#2 E:\\laravel-projects\\api_certose\\app\\Http\\Controllers\\ExhibitController.php(44): App\\Exhibit::findZone('159')
#3 [internal function]: App\\Http\\Controllers\\ExhibitController->retrieveZone('159')
#4 E:\\laravel-projects\\api_certose\\vendor\\illuminate\\container\\BoundMethod.php(29): call_user_func_array(Array, Array)
#5 E:\\laravel-projects\\api_certose\\vendor\\illuminate\\container\\BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#6 E:\\laravel-projects\\api_certose\\vendor\\illuminate\\container\\BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure))
#7 E:\\laravel-projects\\api_certose\\vendor\\illuminate\\container\\Container.php(564): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL)
#8 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(373): Illuminate\\Container\\Container->call(Array, Array)
#9 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(339): Laravel\\Lumen\\Application->callControllerCallable(Array, Array)
#10 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(313): Laravel\\Lumen\\Application->callLumenController(Object(App\\Http\\Controllers\\ExhibitController), 'retrieveZone', Array)
#11 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(275): Laravel\\Lumen\\Application->callControllerAction(Array)
#12 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(260): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute(Array)
#13 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(230): Laravel\\Lumen\\Application->handleFoundRoute(Array)
#14 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(164): Laravel\\Lumen\\Application->handleDispatcherResponse(Array)
#15 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(413): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}()
#16 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(166): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#17 E:\\laravel-projects\\api_certose\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(107): Laravel\\Lumen\\Application->dispatch(NULL)
#18 E:\\laravel-projects\\api_certose\\public\\index.php(28): Laravel\\Lumen\\Application->run()
#19 {main}
"} 

您的PHP代码是正确的,但是Neo4j区分大小写,请尝试更改
$this->belongTomany('App\Zone','belongTo')
$this->belongTomany('App\Zone','belongTo')

是的,您的代码将转换为问题中的查询

编辑

对于您得到的错误,请尝试使用
$exhibit->zones()->edge($exhibit->zones)
而不是
$exhibit->zones()->edge()
如果
$exhibit->zones
的返回值是一个数组,则此操作将不起作用,您必须迭代此数组或在关系的另一端指定特定模型,即:

要检索所有边,请执行以下操作:

$edges = array();
foreach($exhibit->zones as $zone) {
    $edge = $exhibit->zones()->edge($zone);
    array_push($edges, $edge);
}
或者检索特定节点的边,其中
需要替换为关系另一侧的id,或者您可以指定另一个搜索函数,该函数将返回1个Exhibit对象:

 $edge = $exhibit->zones()->edge(Exhibit::find(<id_of_related_node>));
$edge=$exhibit->zones()->edge(exhibit::find());

Hi:)请您解释一下您已经尝试过的内容,以及在示例和相关代码中哪些不起作用?请看:您好:)对不起,这个问题没有完成,我修改了它。您是如何将节点相互关联的?你能提供这方面的代码吗?:)节点之间的关联尚未编码,因为我正在使用一个已填充的数据库,但将来我必须对其进行编码,并且您提供的密码查询返回正确的结果?感谢您的回答,我已编辑了该问题,现在我有一个内部服务器错误操作…这是我所做的一次尝试,现在我添加了正确的堆栈trace@M.Morris看起来是同一个错误,我的建议没有解决它?不,当我尝试使用
$exhibit->zones()->edge($exhibit->zones)
堆栈跟踪说参数1
传递给Vinelab\NeoElount\Elounce\Relations\BelongTomany::edge()必须是Vinelab\NeoElount\Elount\Model的实例,或为null,给定的Illumb\Database\Elount\Collection实例,称为…
。当我尝试使用
$exhibit->zones()->edge()
堆栈跟踪时,将参数2
传递给Vinelab\neoElount\elount\Edges\Finder::first()必须是Vinelab\neoElount\elount\Model的一个实例,给定为空…
@M.Morris我更新了答案,希望这对您有所帮助
$edges = array();
foreach($exhibit->zones as $zone) {
    $edge = $exhibit->zones()->edge($zone);
    array_push($edges, $edge);
}
 $edge = $exhibit->zones()->edge(Exhibit::find(<id_of_related_node>));