I have 3 tables, 1. countries 2. states 3.citites
COUNTRIES contains id, name columns .
STATES contains id, name, country_id columns.
CITIES contains id, name, state_id.
I am accessing cities with hasManyThrough() relation.
Relation:
public function cities()
{
return $this->hasManyThrough('App\Models\City','App\Models\State');
}
How i am fetching citeis:
$countryObj = Country::where('name','like',$country.'%')->first();
$cities = $countryObj->cities->pluck('name');
return response()->json(['cities'=>$cities],200);
I want to concat cites with theirs respective countries. Like: Uk-London