October CMS resources and help articles

Simple and to the point. Optimized by the community.

Add group filter and custom options to a backend list

5
by arrcrown, last modified on December 5th, 2019

Given this table:

| title  | genre     |
| -------| --------- |
| Book 1 | Academia  |
| Book 2 | Biography |
| Book 3 | Children  |
| Book 4 | Fiction   |
| Book 5 | Biography |

In your plugin directory create the following file:

controllers/yourcontroller/config_filter.yaml

inside config_filter.yaml

scopes:
    genre:
        label: Filter Genres
        modelClass: Path\To\Models\Model
        type: group
        conditions: genre in (:filtered)
        options: listGenres

on your model create a method listGenres

    public function listGenres()
    {
        // you can use distinct or groupBy
        return Model::groupBy->('genre')->pluck('genre', 'genre')->toArray();
    }

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?