Currently I get data like so:
->with(['posts' => function ($query) {
$query->active()->available()->limit(1)->with('user');
}])
and it returns the user data as an array of objects which is expected. Because I am using a limit and will only ever need one result, I'd like to return it as a regular object, so instead of:
"data": value,
"posts": [
{
"data": value,
"user": {
"data": value
}
}
]
I'd like to return it as:
"data": value,
"post":
{
"data": value,
"user": {
"data": value
}
}
What's the best way to go about it?
limit(1)withfirst()->with('user')part, and still returnspostsas an array :P