I am using laravel and mysql ,i am joining two tables based on conditions it’s working fine but my requirement was i have to fetch those details inside json ,can anyone give me some idea how to proceed with this scenario ?
Table1::leftJoin(//mycondition)->select('table1.id','table1.name','table2.*')->get()->toArray();
currentResult
[
{
'id':1,
'name':'test',
'tab2id':1,
'tab2name':'tab2'
}
]
ExpectedResult
[
{
'id':1,
'name':'test',
'tab2':{
'tab2id':1,
'tab2name':'tab2'
}
}
]
2
Answers
From Official Docs You can read more
Try this