jeudi 15 juillet 2021

create associative array with key and value generated in for

i´m traying to create associative array, from query in laravel.

public function assignAllCall(Request $request)
    {
        $callList = [];
        $newCall = [];

        for($i=0; $i<count($request->get('calls')); $i++){
            array_push($callList, Listado::where('id', $request->get('calls')[$i])->get());
        }

        for($i=0; $i<count($callList); $i++){
            for($j=$i; $j<count($callList[$i]); $j++){
                $newCall = [
                    'nomape'            => $callList[$i][$j]->nomape,
                    'direccion'         => $callList[$i][$j]->direccion,
                    'provincia'         => $callList[$i][$j]->provincia,
                    'ciudad'            => $callList[$i][$j]->ciudad,
                    'cp'                => $callList[$i][$j]->cp,
                    'telefono'          => $callList[$i][$j]->telefono,
                    'movil'             => $callList[$i][$j]->movil,
                    'id_teleoperadora'  => $request->get('teleoperadora'),
                    'id_estado'         => 1,
                    'fecha_asignacion'  => Carbon::now()->format('Y-m-d H:m:s'),
                    'created_at'        => Carbon::now()->format('Y-m-d H:m:s'),
                ];
                
            }

            print_r($newCall);
            // create call
            //$result = Llamada::create($newCall);
        }  

        //return $result;
    }

i have this function that receive param from ajax and this values it´s ids array.

I need get all data from this ids for get all data and create new calls with this data, for this i have one for to do query and assign to array. after i´m traying to create associative array but when i do print_r always i return same result:

Array
(
    [nomape] => x
    [direccion] => x
    [provincia] => x
    [ciudad] => x
    [cp] => x
    [telefono] => x
    [movil] => x
    [id_teleoperadora] => x
    [id_estado] => x
    [fecha_asignacion] => x
    [created_at] => x
)

always same value. I don´t know if i do well my function or have one better solution for to do this.

Thanks for read and thanks for help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire