Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 - Eloquent result only shows (timestamps, incrementing, exists) when being assigned inside of 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 the town_comments only shows boolean for the timestamps, incrementing and exists.

What am I doing wrong here?

here is how it looks like:

{
id: "1",
name: "tokyo",
similar_stations: {
    timestamps: false,
    incrementing: true,
    exists: true
}
}
like image 586
Ironwind Avatar asked Jul 04 '13 09:07

Ironwind


1 Answers

It's being displayed like that because $townComments is an object automatically encoded to JSON, I forgot the reference where I read it but this is the solution.

$city->town_comments = $townComments->toArray();
like image 98
Bryan P Avatar answered Sep 29 '22 08:09

Bryan P