0

Looking for a solution here that allows searching for a model by it's ID. I am using tntsearch and currently it seems all columns added inside of toSearchableArray() are searchable except for ID. The following is my Order model

    public function toSearchableArray() : array
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'client_request' => $this->client_request
       ];
    }
connorhansen
  • 171
  • 2
  • 15

1 Answers1

1

By default the primary key is not searchable by TNTSearch. If you're using the package directly, you can run

$indexer->includePrimaryKey();

In scout, you could simply add the id to the toSearchableArray method:

public function toSearchableArray() : array
    {
        return [
            'id' => $this->id,
            'model_id' => $this->id,
            'title' => $this->title,
            'client_request' => $this->client_request
       ];
    }
Nenad
  • 3,438
  • 3
  • 28
  • 36