Does nobody have an idea?
Attribute casting, Date Mutators on pivot table of related models
Is it possible to use Attribute Casting and/or Date Mutators on the pivot table of two related Many To Many models?
In one case I have an User and Activity model. The related pivot table has an 'payload' column, this is an column where I store serialized json. I like to cast this attribute to an array.
In an other case I have an User and Action model. The related pivot table has an 'completed_at' column. in this case I wan't to add the 'completed_at' column to the attributes that will be transformed to Carbon objects.
For the first situation I tried, but none worked:
protected $casts = [
'activities.pivot.payload' => 'array',
];
protected $casts = [
'activities.payload' => 'array',
];
To leverage Carbon on the 'completed_at' attribute I tried (but this also did not work):
protected $dates = ['actions.completed_at'];
protected $dates = ['actions.pivot.completed_at'];
Does anyone have any thoughts on this matter?
Please or to participate in this conversation.