Laravel 4 - Eloquent result shows only (timestamps, increment, exists) when assigned inside another object

$city = City::with('station')->where('name',$town)->first(); $townID = 1; $townComments = TownComment::where('town_id',$townID)->get(); $city->town_comments = $townComments; 

When I do this, the result for town_comments shows only boolean for timestamps , incrementing and exists .

What am I doing wrong here?

this is how it looks:

 { id: "1", name: "tokyo", similar_stations: { timestamps: false, incrementing: true, exists: true } } 
+6
source share
1 answer

This is displayed because $townComments is an object automatically encoded to JSON , I forgot the link where I read it, but this is the solution.

 $city->town_comments = $townComments->toArray(); 
+18
source

Source: https://habr.com/ru/post/948691/


All Articles