JanBoehmer
JanBoehmer

Reputation: 555

Exclude models with criteria from Scout

My User model has a nullable column name. I never want to import users, that have no name.

I tried

public function toSearchableArray()
{
    if (!$this->name) {
        return [
            'name' => $this->name,
            'email' => $this->email,
        ];
    }
}

but this has no effect to the import or adding.

Upvotes: 0

Views: 54

Answers (1)

Khang Tran
Khang Tran

Reputation: 2315

This function help to determine if the model should be searchable.

public function shouldBeSearchable(): bool
{
    return (bool) $this->name;
}

Upvotes: 0

Related Questions