Zach Daniel's avatar

BelongsTo returns nested object.

Hi There,

A simple question, is it possible to use with() to return a string instead of a object, and if not what would be the best approach?

$user = User::where('email', $request->email)->with('country')->first();

Would return

"data": { "id": 1, "email": "[email protected]", "country": { "id": 1, "name": "Afghanistan" }, },

And I want

"data": { "id": 1, "email": "[email protected]", "country":"Afghanistan", },

Thanks.

0 likes
3 replies
Zach Daniel's avatar

@Snapey Thanks, I though there would be an easy inline way like adding a function. Thanks, will go this route.

Please or to participate in this conversation.