vendredi 17 novembre 2017

appending another object model to a model Laravel

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, …}

I am getting an array of objects... Let's say i have three eloquent model Comment and User, Answer. I am just showing two comments which belongs to an answer. I want to also show user associated to each comments as you can see there is a user_id which is a foreign key

I want to get something like this using eloquent only ... how do i use append method

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, …}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AXNyIQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire