如何在我的Laravel Vue项目中获取多个关系数据

如何在我的Laravel Vue项目中获取多个关系数据,laravel,vue.js,Laravel,Vue.js,我有一个3个模型“用户”、“评论”、“评论”和“播放” 在用户模型中 public function reviews() { return $this->hasMany('App\Models\Review'); } public function reviewReplys() { return $this->hasMany('App\Models\ReviewReply'); } 审查中的模式

我有一个3个模型“用户”、“评论”、“评论”和“播放”

在用户模型中

    public function reviews()
    {
        return $this->hasMany('App\Models\Review');
    }

    public function reviewReplys()
    {
        return $this->hasMany('App\Models\ReviewReply');
    }
审查中的模式

    public function user()
    {
        return $this->belongsTo('App\Models\User');
    }

    public function reviewReplys()
    {
        return $this->hasMany('App\Models\ReviewReply');
    }
回顾重播模型



    public function user()
    {
        return $this->belongsTo('App\Models\User');
    }

    public function review()
    {
        return $this->belongsTo('App\Models\Reviews');
    }
在我的控制器中

public function getReview($id)
    {
        $review= Review::where('product_id',$id)->with('user','reviewReplys')->paginate(10);
        return response()->json($review);
    }

现在,我运行Review foreach循环,需要Review.reviewReplay.user信息。如何在Review Foreach循环中获取Review Replay用户信息。

您可以按如下操作

$review= Review::where('product_id',$id)->with(['reviewReplys.user'])->paginate(10);
使用(['reviewReplys.user'])
-->它将在Review模型与reviewReplys模型之间建立连接+


查看向用户提供的模型模型

您可以按如下操作

$review= Review::where('product_id',$id)->with(['reviewReplys.user'])->paginate(10);
使用(['reviewReplys.user'])
-->它将在Review模型与reviewReplys模型之间建立连接+

查看向用户提供的模型