Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

List filter with 3 states

by mjauvin, last modified on August 20th, 2023

If you need to filter a list with 3 states, you can use the "switch" filter type as below:

  label: Previous / Current Month
  type: switch
  default: 0
  scope: currentOrPreviousMonth

In your model, add this scope method:

public function scopeCurrentOrPreviousMonth($query, $state)
    return match ($state) {
            // unfiltered query
        "0" => $query,
                // filter for state 1
        "1" => $query->previousMonth(),
                // filter for state 2
        "2" => $query->currentMonth(),



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