There's something weird going on in my Laravel query.
So I'm getting a collection of Users
- if I run it through json_encode
, all its keys/values are there. If I don't, some of them are null. E.g:
Log::info(json_encode($user)); // 'tasks_from_columns' exists
Log::info($user->tasks_from_columns); // null
Log::info($user->email); // exists?
Log::info(get_object_vars($user)); // 'incrementing', 'exists', 'wasRecentlyCreated', 'timestamps'
There's a relation on the User
called tasks_from_columns
. It's there if I json_encode
it, but null if I try to access it directly. Most other keys are accessible though, like email
, id
etc.
If I run it through get_object_vars
, none of them are shown. Just some other ones shown above.
Anyone know what the deal is?
The query itself is
$teamWithTasks = Team::where('id',$team->id)->with(['users' => function($query) use($team){
$query->with(['tasksFromColumns' => function($secondQuery) use($team){
$secondQuery->where('created_at','>',Carbon::now()->subDays(365))->with('project')->whereHas('project', function($thirdQuery) use ($team){
$thirdQuery->where('account_id', $team->account_id);
});
}]);
}])->first();
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire