array_push from array to another array

Antarax :
$adatok = DB::select('SELECT * FROM ingatlan');

foreach ($adatok as $adat) {
  array_push($adatok, Storage::files($adat->id));
}
return $adatok;

Result:

https://i.stack.imgur.com/dLn4H.png

I would like to assign them to existing data. Anyone have any ideas?

Dilip Hirapara :

try as below.

$adatok = DB::select('SELECT * FROM ingatlan');

$return = array();
foreach ($adatok as $adat) {
   $adat->image = Storage::files($adat->id);
   $return[] = $adat;
}
return $return;

as you're using array_push(); it is inserting the value of Storage::files($adat->id) after the $adatok object which you're getting in select query.

What solution does is all records fetched from the table. for each collection, I've added an image element with value and store in an array. Finally, you'll have an array with images.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=198485&siteId=1