Jan 31, 2017
0
Level 1
How to get single row having one column different data.
I have three table Instructors, Inst_avatar, Inst_certificate. where Inst_certificate can have multiple Instructors.
this is my code
protected function getInsrtuctorInfo($vendor_id){
$instructors = DB::table('instructors')
->leftJoin('map_instructors_profile_snap', 'instructors.id', '=', 'map_instructors_profile_snap.instructor_id')
->leftJoin('map_instructors_certificates', 'instructors.id', '=', 'map_instructors_certificates.instructor_id')
->where('instructors.vendor_id', $vendor_id)
->select(DB::raw('
instructors.id as instructor_id, instructors.name as instructor_name, instructors.bio as instructor_bio, map_instructors_profile_snap.link as avatar, map_instructors_certificates.link as certificate'))
->get();
return $instructors;
}
after dd($instructors) i am getting
Collection {#346 ▼
#items: array:2 [▼
0 => {#344 ▼
+"instructor_id": 4
+"instructor_name": "ABC"
+"instructor_bio": """
<p>Lorem Ipsum</p>\r\n
<p> </p>
"""
+"avatar": "1476356667.jpg"
+"certificate": "1476356649.jpg"
}
1 => {#350 ▼
+"instructor_id": 4
+"instructor_name": "ABC"
+"instructor_bio": """
<p>Lorem Ipsum</p>\r\n
<p> </p>
"""
+"avatar": "1476356667.jpg"
+"certificate": "1485842659.jpg"
}
]
}
how can i fox this?
Please or to participate in this conversation.