Reputation: 1496
I cannot find the way. Im using the following Algolia option to create a relationship.
public function toSearchableArray()
{
$array = $this->toArray();
$array['categories'] = $this->categories->map(function ($data) {
return $data['name'];
})->toArray();
return $array;
}
Despite I read php page for array_map I cannot find the way to return more than one value, as an example:
function ($data) {{return $data['name']; return $data['value'] ;})->toArray(),
gives no error but no output too.
Upvotes: 1
Views: 941
Reputation: 9396
Try the following:
$array['categories'] = $this->categories->map(function ($data) {
return [$data['name'], $data['value']];
})->toArray();
You can return an array
instead of trying to return 2 strings
.
Upvotes: 2