Ad

Adding A Scope To A Toolbar Search In October

- 1 answer

As per the documentation at https://octobercms.com/docs/backend/lists#adding-toolbar I have the following code:

config_list.yaml

toolbar:
    buttons: list_toolbar
    search:
        prompt: 'backend::lang.list.search_prompt'
        scope: byEmail

Job.php (model)

public function scopeByEmail($string, $query)
{
    return $query->where('email', 'LIKE', '%' . $string . '%');
}

Unfortuately, this produces an error: Call to undefined method October\Rain\Database\QueryBuilder::byEmail()

I don't understand why this error occurs, because I'm sure that I have the correct code in the model to deal with this.

Ad

Answer

Seems like this was caused by the fact that I have searchable: true for two different models in my columns.yaml

The result seems to be that because I have a scope: byEmail in the config_list.yaml I need to provide a scopeByEmail() method in all of the models that I have defined searchable fields for in columns.yaml

Ad
source: stackoverflow.com
Ad