I'm developing with DataTables in Laravel and trying to make an object manually using collect()
to create a collection. When I push the collection into the DataTable, there is something wrong, and I can't call my object with this $object->attribute.
After I get the error with that, I already tried to call an attribute with $object['attribute'],
and it works well.
Can someone give me insight about the differences and how I can convert $object['attribute']
into $object->attribute
?
This is my query to create object
$result = collect();
$item = collect([
'row' => ($key+1),
'item_id' => $value->uid,
'item' => $value->nama_item,
'sub_kategori' => $value->sub_jenis_item->sub_jenis_item,
'kategori' => $value->jenis_item->jenis_item,
'gudang_id' => $id_gudang
]);
$result->push($item);
Accessing
$object['attribute']
means$object
is anarray
and accessing$object->attribute
means$object
is anobject
.To convert
array
toobject
:Additionally, to convert
object
toarray
: