Home > Enterprise >  Attempt to read property "id_tahun" on array
Attempt to read property "id_tahun" on array

Time:07-15

i try to transform it with eloquent, but the error pop-up Error Notification"Attempt to read property "id_tahun" on array"

$factpelanggan = DB::connection('clickhouse')
    ->select('SELECT id_tahun, t.tahun, l.id_lokasi
    from dim_tahun t, dim_lokasi l');

    foreach ($factpelanggan as $value) {
        $id_tahun[]=$value->id_tahun;
        $id_lokasi[]=$value->id_lokasi;
        $tahun[]=$value->tahun;
    }

CodePudding user response:

The select query in Laravel returns an array: https://laravel.com/docs/9.x/database#running-a-select-query You can change your code like that:

    foreach ($factpelanggan as $value) {
        $id_tahun[]=$value['id_tahun'];
        $id_lokasi[]=$value['id_lokasi'];
        $tahun[]=$value['tahun'];
    }
  • Related