doremi666
doremi666

Reputation: 141

Laravel Additional Attributes added to both models in many-to-many relationship

I would like to added created_at and updated_at in the pivot table(user_role) but I am not sure whether it is necessary to added withTimestamps() in both models (e.g users and roles) or add it to one of the models will do?

Upvotes: 0

Views: 50

Answers (1)

Chin Leung
Chin Leung

Reputation: 14921

You need to add in the relation of both model. If you only add it to your App\User model, then the timestamp will only be maintained when retrieving or updating via the user model.

You can read more about many to many relations here: https://laravel.com/docs/7.x/eloquent-relationships#many-to-many

Upvotes: 1

Related Questions