Hello ,
this is my eloquent query .
$this->plannings = DB::table("plannings as p")
->select(...)
->orderByRaw(" u.name asc, date asc , quarter asc")
->get()
the result is :
Illuminate\Support\Collection {#1603 ▼
#items: array:8 [▼
0 => {#1473 ▼
+"dep_id": 6
+"user_id": 6
+"user_name": "Abc name"
+"date": "2022-11-01"
+"quarter": "Q1"
+"comment": null
+"to_invoice": false
+"adhoc": false
+"flight": false
+"telework": "On customer site"
+"teamleader_company_name": "Public holiday"
+"activity_type_name": null
+"teamleader_deal_name": null
+"planning_absence_id": 6478
+"label_hr": "Public hol."
+"label": "Public holiday"
}
1 => {#1477 ▼
+"dep_id": 6
+"user_id": 6
+"user_name": "Abc name"
+"date": "2022-11-01"
+"quarter": "Q2"
+"comment": null
+"to_invoice": false
+"adhoc": false
+"flight": false
+"telework": "On customer site"
+"teamleader_company_name": "Public holiday"
+"activity_type_name": null
+"teamleader_deal_name": null
+"planning_absence_id": 6478
+"label_hr": "Public hol."
+"label": "Public holiday"
}
2 => {#1459 ▼
+"dep_id": 6
+"user_id": 6
+"user_name": "Abc name"
+"date": "2022-11-01"
+"quarter": "Q3"
+"comment": null
+"to_invoice": false
+"adhoc": false
+"flight": false
+"telework": "On customer site"
+"teamleader_company_name": "Public holiday"
+"activity_type_name": null
+"teamleader_deal_name": null
+"planning_absence_id": 6478
+"label_hr": "Public hol."
+"label": "Public holiday"
}
3 => {#1457 ▼
+"dep_id": 6
+"user_id": 6
+"user_name": "Abc name"
+"date": "2022-11-01"
+"quarter": "Q4"
+"comment": null
+"to_invoice": false
+"adhoc": false
+"flight": false
+"telework": "On customer site"
+"teamleader_company_name": "Public holiday"
+"activity_type_name": null
+"teamleader_deal_name": null
+"planning_absence_id": 6478
+"label_hr": "Public hol."
+"label": "Public holiday"
}
4 => {#1476 ▼
+"dep_id": 6
+"user_id": 6
+"user_name": "Abc name"
+"date": "2022-11-11"
+"quarter": "Q1"
+"comment": null
+"to_invoice": false
+"adhoc": false
+"flight": false
+"telework": "On customer site"
+"teamleader_company_name": "Public holiday"
+"activity_type_name": null
+"teamleader_deal_name": null
+"planning_absence_id": 6479
+"label_hr": "Public hol."
+"label": "Public holiday"
}
5 => {#1443 ▼
+"dep_id": 6
+"user_id": 6
+"user_name": "Abc name"
+"date": "2022-11-11"
+"quarter": "Q2"
+"comment": null
+"to_invoice": false
+"adhoc": false
+"flight": false
+"telework": "On customer site"
+"teamleader_company_name": "Public holiday"
+"activity_type_name": null
+"teamleader_deal_name": null
+"planning_absence_id": 6479
+"label_hr": "Public hol."
+"label": "Public holiday"
}
6 => {#1627 ▶}
7 => {#1625 ▶}
]
#escapeWhenCastingToString: false
}
As you can see for user_id:6 and the date:'2022-11-01' I have all quarters :Q1,Q2,Q3 and Q4 so it's okay
But for the user user_id:6 and the date:'2022-11-02' for example there is no quarters rows , so I need to add 4 elements like :
[ "user_id" => null, "user_name" => "Abc name","date" => "2022-11-02","quarter" => "Q1"],
[ "user_id" => null, "user_name" => "Abc name","date" => "2022-11-02","quarter" => "Q2"],
[ "user_id" => null, "user_name" => "Abc name","date" => "2022-11-02","quarter" => "Q3"],
[ "user_id" => null, "user_name" => "Abc name","date" => "2022-11-02","quarter" => "Q4"]
Any Idea ? from where can I start?