Why not just use the relation? Each Comment belongsTo a User, so all you need to do is create a relation in Comment model and then you can do something like this
$comments = Comment:with('user')->get();
...
you can than access user name for a particular one $comment
$comment->user->username
Hey Torch!
well this is how i did it, but i want to access it on client side via - i mean, i want it to be converted to Json with not only the user id (which is part of the comment, but also extra attributes which are only inside the user model
Sorry avieln, I dont understand what you are trying to achieve :/ Do you really need it in json? You can access the user model attributes of comment by the code i posted above. Maybe elaborate a little more where is the problem.
Not to mention, that the collection in laravel is returned as json automatically (I think). If not there is always toJson() method
$comments = Comment:with('user')->get()->toJson();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community