Search code examples
laravel-4algolia

laravel algolia send only specific fields


Is there a way with laravel and algolia package to update to the index not ALL the fields but only the ones i need?


Solution

  • You can use getAlgoliaRecord() method in your model and return array from it with attributes you want to index.

    Example:

    use Illuminate\Database\Eloquent\Model;
    
    class Contact extends Model
    {
        use AlgoliaEloquentTrait;
    
        public function getAlgoliaRecord()
        {
            return [
                'indexedAttribute' => $this->indexedAttribute, 
                'otherIindexedAttribute' => $this->otherIindexedAttribute, 
                'nextIndexedAttribute' => $this->nextIndexedAttribute, 
            ];
        }
    }