将另一个对象模型附加到模型Laravel

时间:2017-11-17 19:00:48

标签: laravel laravel-5 laravel-5.3 laravel-eloquent

comment:Array(2)
    0:{id: 1, user_id: 10, answer_id: 6, comment_content: "This is first comment ever in this", parent_id: 0, …}
    1:{id: 6, user_id: 10, answer_id: 6, comment_content: "This is commenting again let's see whether it works or not, It should work.", parent_id: 0, …}

我得到一个对象数组...... 假设我有三个雄辩的模型评论和用户,答案。我只是展示了两条属于答案的评论。我还想显示与每条评论关联的用户,因为您可以看到有一个user_id是外键

我想使用雄辩的方式得到类似的东西...我如何使用追加方法

comment:Array(2)
    0:{id: 1, user_id: 10, name: "Jonh Doe" email: 'john@xyz.com', answer_id: 6, comment_content: "This is first comment ever in this", parent_id: 0, …}
    1:{id: 6, user_id: 10, name: "Foo", email:'foo@xyz.com', answer_id: 6, comment_content: "This is commenting again let's see whether it works or not, It should work.", parent_id: 0, …}

0 个答案:

没有答案