Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

subakarank's avatar

How to set date mutator for pivot date fields

I have pivot table fields such as --start_date and end_date. --

--How to set these field as date fields ( mutator).. -- like protected dates = ['created_at', 'updated_at']

I try the following method. But it does not work. No impact when access the start_date and date_date fields

public function getStartDateAttribute($value) {
        return Carbon::parse($value)->format('d-m-Y');
    }
    public function getEndDateAttribute($value) {
        return Carbon::parse($value)->format('d-m-Y');
    }
    public function getPivotStartDateAttribute($value) {
        return Carbon::parse($value)->format('d-m-Y');
    }
    public function getPivotEndDateAttribute($value) {
        return Carbon::parse($value)->format('d-m-Y');
    }
0 likes
1 reply

Please or to participate in this conversation.