Ashraam
139
0
General

Algolia search (Scout) with multiples fields

Posted 1 year ago by Ashraam

Hi everyone,

Let' say I want to create a phone book for a big company with multiples offices. My database is composed by 3 tables:

  • User
  • City (represent the office's location)
  • Role (a User can have multiple roles)

I'd like to create a form with 3 different fields to perform the query, how can I do that ?

For now I've got only 1 field and this is my main model User

    public function city()
    {
        return $this->belongsTo(City::class);
    }

    public function roles()
    {
        return $this->belongsToMany(Role::class);
    }

    public function toSearchableArray()
    {
        $office = $this->city;

        $array = [
            'name' => $this->name,
            'phone' => $this->phone,
            'postal_code' => $office->postal_code,
            'city' => $office->name,
        ];

        return $array;
    }

How would you do a research with Algolia and add filters to the query (City and Roles) ?

How should I store Roles ? Plain text ?

Thank you

Please sign in or create an account to participate in this conversation.