I'm using Laravel 8 and in my application, I have Belongs to Many relations with a custom model, and I want to remove the 'updated_at' field.
Relation
public function tracks() { return $this->belongsToMany(Track::class) ->using(CollectionTrack::class) ->withPivot('sort' , 'created_at' , 'id'); } Custom model
class CollectionTrack extends Pivot { use Sortable; public const UPDATED_AT = null; public $incrementing = true; public static function enableAutoSort () { return false; } } The issue is that when I want to sync, it tries to fill the updated_at field.
Column not found: 1054 Unknown column 'updated_at' in 'field list'
However, I removed the updated_at from the Model using the following line.
public const UPDATED_AT = null; And also, only get the created_at in withPivot.
When I remove the created_at from withPivot, the issue goes away, but in that case, when I retrieve the data created_at won't be in the fields.
Note: my goal is to disable the updated_at timestamp and only have created_at so when I attach a new record, the created_at set and when I retrieve it, the model has these pivot fields 'sort', 'created_at', 'id.'