if have try join and subquery but its not coming in this format
Jan 28, 2023
11
Level 1
Result from two table in single query in Laravel
#attributes: array:2 [▼
"id" => 1
"name" => "Saint Lucia country"
"city" => array:8 [▼
0 => App\Models\City {#1449 ▶}
1 => App\Models\City {#1436 ▶}
2 => App\Models\City {#1462 ▶}
3 => App\Models\City {#1475 ▶}
4 => App\Models\City {#1494 ▶}
5 => App\Models\City {#1503 ▶}
6 => App\Models\City {#1509 ▶}
7 => App\Models\City {#1533 ▶}
]
if have country table and city table. I want to get a country and cities related to it in above format how can it do this. I want this result but in single query in Laravel please someone help.
if above format ** id** and name is coming from country table and city is in array format and its coming from city table
Level 102
@abdulrehman176617 two queries is good. More than that is bad. In theory you can use a single query with join, but it's a lot of work to get working and most likely won't be faster
2 likes
Please or to participate in this conversation.