lundi 18 mars 2019

push an array while foreach other array laravel

I'm using laravel package commentable by faustbrian. i've been getting the comment for a post using just like in documentation in github . I want to search the information for user who post the comment, e.g the user avatar, address, and other information as well. I want to include the user information (which is an array) to the current position index of array (while for each i push it). the problem is, i tried using array_push, array_merge and $data[$key]=>$value as well. but none of them is working when i dd the variable. please help.

public function notaPengurusan($id){
    $comments=Complaint::findOrFail($id)->comments->toArray();
    foreach ($comments as $comment){
        $creator=User::findOrFail($comment['creator_id'])->toArray();
        array_push($comment,$creator);
    }
    dd($comments);
    return view('complaint::notapengurusan',compact('comments'));
}

image when i dd the image this is simply as in commentable package but not user information



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire