jeudi 12 décembre 2019

How to array merge in laravel

I have a problem here, I want to combine 2 arrays into 1, I've tried using array_merge from php, and merge () from laravel but nothing works

$vendor = Vendor::find($id)->toArray();
        $vendor_detail = Vendor_detail::where('vendor_id',$id)->get();
        $plucked = $vendor_detail->pluck('vendor_name','vendor_value');

//$plucked is EAV database

        $merged = array_merge($plucked, $vendor);

        // $merged = $vendor->merge($plucked)->all(); 
        dd($merged);

I think because the array is different, there array $plucked

#items: array:10 [▼
    "user_email" => "cobaupdatelagi@gmail.com"

  ]

and there my array in $vendor


array:15 [▼
  "vendor_id" => 39
  "province" => "ACEH"

]

the output that I want

$somearray =[
   "vendor_id" => 39
  "province" => "ACEH"
  "user_email" => "cobaupdatelagi@gmail.com"

]


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire