How to separate number ? 10 000 instead of 10000?

Hi I’m currently working with laravel, a php framework and my @{{result.code}} is sometimes long numbers and i would like to separate them when it’s more than a thousand.

Thanks for any ideas or solutions!

Hi Victos,

The very best way is to formast this data before you index them to Algolia. With Scout you can easily do that with the toSearchableArray() method in your model.

public function toSearchableArray()
    $data = $this->toArray();

    $data['code_formatted'] = number_format($data['code'];

    return $data;

Then in algolia you will have this new attribute, which will be available in your template

@{{ result.code_formatted }}

Will that work for you?

1 Like

Hi and thank you for responding but i don’t really understand where I have to write this function and i never used scout ? What’s model ? and

What are you using to plug Algolia into your Laravel app? Our package?

Hi ( sorry for responding so lately)
I am directly adding my objects in the dashboard. How Can I add this Scout function in my blade.php ? Thank you.

If you add your data in the dashbpard, you can also add this extra info manually in your records.

I would recommend you to have a look at Scout, unless these data don’t exist in your database.

We installed Scout and it worked perfectly ! Thank you !

1 Like