This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

planetadeleste
planetadeleste

How can I filter by timestamps and display the date correctly?

Using this yaml config, the filter work fine, but the displayed text is [object Object] Filter by created_at

# ===================================
# Filter Scope Definitions
# ===================================
scopes:
    group:
        label: Group
        modelClass: PlanetaDelEste\Mag\Models\MagGroup
        nameFrom: created_at
        conditions: group_id in (:filtered)

Thanks!

Last updated

shina
shina

It happens because of $dates attribute modifier. (see $dates on https://octobercms.com/docs/database/model#attribute-modifiers)

I did not try it, but maybe if you use an alias for created_at you can use the raw value.

nameFrom: created_at as created_at_time

Something like this.

Last updated

planetadeleste
planetadeleste

Thanks @shina for your fast response. I know dates are a Carbon/DateTime object, but I don't know how to show in filters the value (in string). I try your code, but doesn't show any text.

planetadeleste
planetadeleste

SOLVED.

I found the solution. And is simple, only created a custom attribute for the Group model.

public function getCreatedDateAttribute() {
    return $this->created_at->toDateString();
}

And for the config_filter.yaml

nameFrom: created_date

It works. The custom attribute can return the datetime in any format, using Carbon/DateTime.

Thanks

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.