Joydip's avatar

create a PHP multidimensional array in laravel 5.4 for the mysql join statement which which return multiple row for a user id

I have a jobs table, which has a job id and some other stuff

jobs

id | job_title | job_profile |

1 | software engg | java developer |

and another table could be job location table

job_location

Id | city | job_id

1 | Delhi | 1

2 | Mumbai | 1

Here job_location.job_id is the jobs.id

Now I want to fetch a job consisting of all the possible city.

I tried

$job_ids = DB::table('jobs'); $job_ids->where ('jobs.id', $id); $job_ids->join('job_location', 'jobs.id', '=', 'job_location.job_id');

$job_ids = $job_ids->get(); Now its giving me two object of jobs, one for each cities. Output:

[{"id":1,"job_title":"Job Title Software Developer","job_profile":"Associate Software Developer","city":"Delhi"},{"id":1,"job_title":"Job Title Software Developer","job_profile":"Associate Software Developer","city":"Mumbai"}] Expected Result:

[{"id":1,"job_title":"Job Title Software Developer","job_profile":"Associate Software Developer","city":{"Delhi","Mumbai"}}] Any help would be appreciated. Thanks

Note: I am using laravel query builder

0 likes
1 reply

Please or to participate in this conversation.