My controller of a socials table outputs the following :
[
{
"id": 4,
"value": "FaAlgolia",
"name": "zaefzaef",
"profile_id": 4,
"order": 9000,
"created_at": "2021-05-17 20:25:03",
"updated_at": "2021-05-17 20:25:03"
},
{
"id": 5,
"value": "FaAlipay",
"name": "azdadzzad",
"profile_id": 4,
"order": 9000,
"created_at": "2021-05-17 20:41:53",
"updated_at": "2021-05-17 20:41:53"
}
]
Each of those elements belongs to a profile.
Profiles table :
Socials table :
In profiles table I have a URL column. I would want to return it in my array so the output will look like this.
[
{
"id": 4,
"value": "FaAlgolia",
"name": "zaefzaef",
"profile_id": 4,
"order": 9000,
"created_at": "2021-05-17 20:25:03",
"updated_at": "2021-05-17 20:25:03"
"url": the url from profiles table
},
{
"id": 5,
"value": "FaAlipay",
"name": "azdadzzad",
"profile_id": 4,
"order": 9000,
"created_at": "2021-05-17 20:41:53",
"updated_at": "2021-05-17 20:41:53"
"url": the url from profiles table
}
]
I tried making a join like the following but it returns both elements with all url. So the output is the first array with both urls then second element with both urls:
public function profile($id)
{
$data = DB::table('socials')->where('profile_id','=', $id)
->join('profiles', 'url', '=', 'profiles.url')
->groupBy('profile_id')
->get();
return $data;
}

