Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel中使用()获取数据嵌套关系_Php_Laravel_Eloquent - Fatal编程技术网

Php 在Laravel中使用()获取数据嵌套关系

Php 在Laravel中使用()获取数据嵌套关系,php,laravel,eloquent,Php,Laravel,Eloquent,我有一个模型文件“Student”,其中包含以下关系: public function implementations() { return $this->hasMany(Implementation::class); } 在我的实现模型中,我有以下关系: public function score() { return $this->belongsTo(Score::class, 'id', 'implementation_id');

我有一个模型文件“Student”,其中包含以下关系:

 public function implementations()
 {
       return $this->hasMany(Implementation::class);
  }
在我的实现模型中,我有以下关系:

public function score()
    {
        return $this->belongsTo(Score::class, 'id', 'implementation_id');
    }

public function project()
    {
        return $this->belongsTo(Project::class);
    }
我想检索一个包含所有数据的表

我试过这个

public function getStudents($id)
{
    $event = Event::where('id', $id)->first();
    $data = $event->students()->with('implementations')->get();

    return response()->json($data);
}
它起作用了。但是我没有我想要的结果。我还想用
项目
评分
关系恢复
实施
数据

我试过了,但没用

public function getStudents($id)
{
    $event = Event::where('id', $id)->first();
    $data = $event->students()->with('implementations')->with('project', 'score')->get();

    return response()->json($data);
}

非常感谢你的帮助

您尝试过使用('students'、'students.implements')事件::吗?您可以使用点表示法加载关系的关系。

您尝试过使用('students','students.implements')的
事件::了吗?您可以使用点表示法加载关系的关系。

您尝试过使用('students'、'students.implements')的
Event::了吗
?您可以使用点表示法加载关系的关系。这很有用<代码>$data=$event->students()->with('implementations','implementations.project','implementations.score')->get()谢谢!没问题。作为未来观众的答案发布。您是否尝试过使用('students'、'students.implements')
?您可以使用点表示法加载关系的关系。这很有用<代码>$data=$event->students()->with('implementations','implementations.project','implementations.score')->get()谢谢!没问题。作为未来观众的答案发布。我使用此关系,无法在关系$sql->with(['postable'=>函数($sql)use($is_detail){if($is_detail&&in_数组(config('general.post_type_index.search'),['postable.post_type_id')){$sql->with([“postable”];}}}]);我使用这个关系,并且我无法在关系$sql->with(['postable'=>函数($sql)use($is_detail){if($is_detail&&in_数组(config('general.post_type_index.search'),[“postable.post_type_id]”)中使用急切加载关系值){$sql->with([“postable”];}}]);