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

AlexeiKo
AlexeiKo

I have this in model: ` fields.yaml

special_offer:

    label: special_offer

    type: Switch

    default: true

` DB field is tinyint(1)

working good!

But I want to show in list not 0 or 1, but available/not available. I can store string, but I prefer to convert it.

this accessor:

 public function getSpecialOfferAttribute ($value){

    return ( $value === 1 ) ? 'available' : 'not available' ;

}

will show right in list, but wrong in form, since switch accepts only 0/1

How can I do this?

Thanks

candrabeqx
candrabeqx

Hi, I know this is very old, but for the sake of completion, I'll try to solve answer your question.

If you'd like to display custom message on the List, the best option is to use new attribute name. Use this on your columns.yaml

special_offer_text:
    label: 'Special Offer'
    type: text

and then add this to your model:

public function getSpecialOfferTextAttribute(){
    return ( $this->special_offer == 1 ) ? 'Available' : 'Not Available' ;
}

1-2 of 2

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