mardi 24 novembre 2015

How to save multidimensional array in Laravel

Good afternoon !

I am creating a private chat , and I get the first objective , get the message and users with the following code.

public function getEnviarMensajes($id,$identificador){
        $user = User::find($identificador);
        $idReceptor =  $user->id;
        $idEmisor = Auth::user()->id;

        $mesageuser = MessageUser::with('user')->with('message')->get();
        $name = [];
        $content = [];
        foreach($mesageuser as $users){
            foreach($users->message as $mensajes){
                if($users->user->id==$idEmisor){

                $name[] = $users->user->name;
                echo "<p>";
                $content[] = $mensajes->contenido;
                echo "<p>";
                echo $mensajes->created_at;
                echo "<p>";

                }
                if($users->user->id==$idReceptor){

                $name[] = $users->user->name;
                echo "<p>";
                $content[] = $mensajes->contenido;
                echo "<p>";
                echo $mensajes->created_at;
                echo "<p>";
                }
            }

        }

However , I have a problem , this results i need to "join" , in many ocasions I used an array , but in this case ? How I can save differents rows in Laravel ?

Could anyone helps to me ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire