mercredi 13 mars 2019

Laravel Join Query for multiple tables

I want to write a query regarding this below response. I tried by writing a query by joining multiple tables its works but, I want to add my years table data in the array, not the separate array of objects.

return response()->json([
                'status' => 'success',
                'code' => 200,
                'message' => 'student data fetch successfully',
                'data' => [
                    [
                        'student_id' => 1,
                        'student_name' => 'Shweta B',
                        'profile_photo' => 'http://example.com/image.jpg',
                        'school_id' => 99,
                        'school_name' => 'XYZ School',
                        'year' => ['2019', '2018', '2017']
                    ]
                ]
            ]);

I tried this,

$students = DB::table('parent_students')
                ->join('parents', 'parents.id', '=', 'parent_students.parent_id')
                ->join('students', 'students.id', '=', 'parent_students.student_id')
                ->join('student_schools', 'student_schools.student_id', '=', 'students.id')
                ->join('schools', 'schools.id', '=', 'student_schools.school_id')
                ->join('years', 'years.id', '=', 'schools.year_id')
                ->where('parents.id', '=', $input['parent_id'])
                ->get();

I Need years in the array instead of a different object.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire