Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

cant use toSearchableArray method #116

Closed
bsormagec opened this issue Mar 22, 2021 · 3 comments
Closed

cant use toSearchableArray method #116

bsormagec opened this issue Mar 22, 2021 · 3 comments

Comments

@bsormagec
Copy link

bsormagec commented Mar 22, 2021

I can't use toSearhableArray for eager loading. When I use eager loading features index not getting values. Any idea ?

    public function toSearchableArray(): array
    {
        return [
            $this->stock_code,
            $this->category->name,
            $this->name,
            $this->description,
            $this->status,
            $this->is_online,
            $this->is_active,
            optional($this->brand)->name,
            $this->mainProduct,
        ];
    }
@mmachatschek
Copy link
Collaborator

Hi @bsormagec,

this is not MeiliSearch specific. And more of a laravel/scout issue. You can try to do:

    public function toSearchableArray(): array
    {
       $this->load('brand');

        return [
            $this->stock_code,
            $this->category->name,
            $this->name,
            $this->description,
            $this->status,
            $this->is_online,
            $this->is_active,
            optional($this->brand)->name,
            $this->mainProduct,
        ];
    }

@bsormagec
Copy link
Author

bsormagec commented Mar 23, 2021

I am checking it send post to meilisearch instance

  32 => array:8 [
    "stock_code" => "STCK12344321"
    "category" => "Fruits"
    "name" => "test variant1 name"
    "description" => "test variant1 description"
    "status" => 0
    "is_online" => 0
    "is_active" => null
    "brand" => "Coogie"
  ]

but I can't see any record on meilisearch don't understand what is the problem. If I see $this->toArray() it works but when I try to manipulate array key's its not sending values to meilisearch. do you have an idea @mmachatschek

@bsormagec
Copy link
Author

I fixed problem and sorry for disturbing :) I forgot to add id field to toSearchableArray Method :) thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants