How To Create a Refinement List with the following DATA

Im trying to create a Refinement List with the following product data:

  • Table 1: Product
  • Table 2: Product Details.

With table Product, all the desired data is retrieved perfectly creating a json file very similar to algolia ecommerce best buy example.
“id”: “3953367”
“name”: “360fly - Panoramic 360° HD Video Camera - Black”,
“popularity”: 9999,
“rating”: 5,
“objectID”: “9131042”

On the other hand, Table 2 -> Product Details have the following structure:

id - productId - name - value.
1 - 3953367 - Operating System - Android 4.4 KitKat
2 - 3953367 - Voice Activated - Yes
3 - 3953367 - Processor Speed - 1.2 gigahertz

as you can see, 1 single product can display more than 3 options for facet. But I dont know how to structure that data to create a refinement list like this:

As an example, how can I create the json to allow people to refine using Operating System. I was thinking to use a @foreach inside ToSearchableArray Function where ->

$record[$this->productdetails->map(function($data) {return [$data[‘name’]];})->toArray()]
$this->productdetails->map(function($data) {return [$data[‘value’]]; })->toArray();

but in this example i receive error:

Illegal offset type

Any Example Appreciated. Im using Laravel Scout with Algolia.

My code updated: I updated my ToSearchableArray code.

public function toSearchableArray()
$record[‘name’] = $this->productName;
$record[‘description’] = $this->productSpecification;
$record[‘brand’] = $this->productBrand;
$record[‘color’] = $this->color;
$new_array = ;

foreach ($this->productdetails as $record) {
    $new_array[$record['name']] = $record['value'];
return $record;


But currently Im receiving array_merge(): Argument #1 is not an array

Hi siherrera1,

I’m afraid I’m struggling to make sense of the toSearchableArray implementation you’ve provided in your last post.

It doesn’t look like you do anything with the $new_array variable, and you treat each instance of the product details association as an array (where I believe it is an object - please correct me if I’m wrong).

Please see the below example of a toSearchableArray method, that combines attributes into one array. There are multiple ways to acheive this.

Looking forward to hear how you get on.

1 Like

Thank you so much! working perfect (i dont know why I make it so difficult). best regards