Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $commenti = Commenti::select('commenti.id AS id','users.username AS username',
- 'commenti.id_commenti AS id_commenti','commenti.commento AS commento','commenti.created_at AS created_at')
- ->leftJoin('users', 'users.id', 'commenti.id_users')
- ->where('id_schede', '=', $request['id_schede'])
- ->get();
- $array_commenti = [];
- $array_subcommenti = [];
- foreach ($commenti as $cmt) {
- if(!$cmt->id_commenti){
- $temp_obj = new \stdClass();
- $temp_obj->id = $cmt->id;
- $temp_obj->username = $cmt->username;
- $temp_obj->id_commenti = $cmt->id_commenti;
- $temp_obj->commento = $cmt->commento;
- // $temp_obj->created_at = $cmt->created_at;
- $temp_obj->subcomment = [];
- array_push($array_commenti, $temp_obj);
- }
- else {
- $temp_obj = new \stdClass();
- $temp_obj->id = $cmt->id;
- $temp_obj->username = $cmt->username;
- $temp_obj->id_commenti = $cmt->id_commenti;
- $temp_obj->commento = $cmt->commento;
- // $temp_obj->created_at = $cmt->created_at;
- $temp_obj->subcomment = [];
- $temp_obj->bool = false;
- array_push($array_subcommenti, $temp_obj);
- }
- }
- foreach ($array_subcommenti as $cmt) {
- if($cmt->bool == false){
- $temp_obj = new \stdClass();
- $temp_obj->id = $cmt->id;
- $temp_obj->username = $cmt->username;
- $temp_obj->id_commenti = $cmt->id_commenti;
- $temp_obj->commento = $cmt->commento;
- // $temp_obj->created_at = $cmt->created_at;
- $temp_obj->subcomment = [];
- foreach ($array_commenti as $ar_cmt) {
- if($ar_cmt->id == $temp_obj->id_commenti){
- array_push($ar_cmt->subcomment, $temp_obj);
- $cmt->bool = true;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement