I have a collection of documents in Laravel that includes objects due to eloquent relationships. The structure of the array is as follows:
Documents:
[
{
"id": 6,
"name": "document",
"supplier": {
"id": 5,
"name": "H.B.C",
}
},
{
"id": 5,
"name": "document",
"supplier": {
"id": 5,
"name": "H.B.C",
}
},
{
"id": 4,
"name": "document",
"supplier": {
"id": 4,
"name": "Avrora",
}
}
]
I am aiming to extract unique supplier names using lodash. In the example above, I would like to retrieve H.B.C and Avrora without duplicates.
This is my attempt:
CollectionSuppliers () {
return uniq(this.Documents.supplier.map(({ name }) => name))
},
However, an error occurs:
Cannot read properties of undefined (reading 'map')