i want to foreach using 3 arrays, i have 3 array :
- data
- data1
- master
i use array_merge to merge array data1 and data and use it as first array in my foreach.
this is what i did so far, and i get this error in my View
Undefined property: stdClass::$nama_kamera
controller :
$master=\DB::table('tb_detail_rental_kamera')
->select('*')->where('id_rental_kamera','=', $id_rental)->get();
$data1=\DB::table('tb_aksesoris_kamera')
->join('tb_detail_rental_kamera','tb_aksesoris_kamera.id_aksesoris','=','tb_detail_rental_kamera.id_data_kamera')
->select('*')->where('id_rental_kamera','=', $id_rental)->get();
$data=\DB::table('db_data_kamera')
->join('tb_detail_rental_kamera','db_data_kamera.id_data_kamera','=','tb_detail_rental_kamera.id_data_kamera')
->select('*')->where('id_rental_kamera','=', $id_rental)->get();
$combine=array_merge($data1,$data);
return view('data-stok')->with(['data' => $combine, 'master' => $master]);
view :
@foreach ($master as $view => $ser)
<tr>
<td></td>
<td></td>
<td></td>
@if(App\DataKamera::where(['id_data_kamera' => $ser->id_data_kamera])->count() > 0)
<td></td>
@else
<td></td>
@endif
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
@endforeach
array :
array:2 [▼
"data" => array:4 [▼
0 => {#231 ▼
+"id_aksesoris": "t"
+"nama_aksesoris": "test"
+"harga": 2121
+"toko": "5345"
+"id_detail_rental_kamera": 22
+"id_rental_kamera": 11
+"id_data_kamera": "t"
+"tarif_sewa": 7557
+"subtotal": 75675
+"keterangan": "egerg"
}
1 => {#232 ▼
+"id_aksesoris": "t"
+"nama_aksesoris": "test"
+"harga": 2121
+"toko": "fwefe"
+"id_detail_rental_kamera": 44
+"id_rental_kamera": 11
+"id_data_kamera": "t"
+"tarif_sewa": 11
+"subtotal": 11
+"keterangan": "11"
}
2 => {#233 ▼
+"id_data_kamera": "11"
+"nama_kamera": "test"
+"jenis_kamera": "test"
+"merk_kamera": "test"
+"spesifikasi": "test"
+"tanggal_beli": "2017-02-08"
+"tarif_sewa": 11
+"keterangan": "11"
+"toko": "fwefe"
+"id_detail_rental_kamera": 11
+"id_rental_kamera": 11
+"subtotal": 11
}
3 => {#234 ▼
+"id_data_kamera": "11"
+"nama_kamera": "test"
+"jenis_kamera": "test"
+"merk_kamera": "test"
+"spesifikasi": "test"
+"tanggal_beli": "2017-02-08"
+"tarif_sewa": 11
+"keterangan": "11"
+"toko": "fwefe"
+"id_detail_rental_kamera": 33
+"id_rental_kamera": 11
+"subtotal": 11
}
]
"master" => array:4 [▼
0 => {#225 ▼
+"id_detail_rental_kamera": 11
+"id_rental_kamera": 11
+"id_data_kamera": "11"
+"tarif_sewa": 11
+"subtotal": 11
+"keterangan": "11"
+"toko": "fwefe"
}
1 => {#227 ▼
+"id_detail_rental_kamera": 22
+"id_rental_kamera": 11
+"id_data_kamera": "t"
+"tarif_sewa": 7557
+"subtotal": 75675
+"keterangan": "egerg"
+"toko": "5345"
}
2 => {#228 ▼
+"id_detail_rental_kamera": 33
+"id_rental_kamera": 11
+"id_data_kamera": "11"
+"tarif_sewa": 11
+"subtotal": 11
+"keterangan": "11"
+"toko": "fwefe"
}
3 => {#229 ▼
+"id_detail_rental_kamera": 44
+"id_rental_kamera": 11
+"id_data_kamera": "t"
+"tarif_sewa": 11
+"subtotal": 11
+"keterangan": "11"
+"toko": "fwefe"
}
]
]
via Janotama