lundi 4 décembre 2017

Laravel Join 2 tables , one data from first table and multiple row from second table

FirstTable

id | name |


1 | student1 |

2 | student2 |

3 | student3 |

4 | student4 |

==============================

SecondTable

Id | stud_id | subject | mark


1 | 1 | maths | 50

2 | 1 | english | 45

3 | 2 | maths | 20

4 | 3 | maths | 40

How would i query in laravel with the above table structure.. i need outpus as

{

"id": 1,

"name":"student1"

"marks":[

{

"subject":"maths",

"marks":50,

}

{

"subject":"emglish",

"marks":45,

}

]

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire