Timestamps are not updating while attaching data in pivot table

LaravelLaravel 4Eloquent

Laravel Problem Overview


I'm creating a row in pivot table using the following attach statement.

$music = Music::find(1);
$music->users()->attach(1);

This inserting a row in pivot table but, It is not updating the timestamp. The timestamp remains 0000-00-00 00:00:00

Is there any way to update the timestamps in pivot table. ?

Thanks in advance,

Laravel Solutions


Solution 1 - Laravel

> If you want your pivot table to have automatically maintained > created_at and updated_at timestamps, use the withTimestamps() > method on the relationship definition.

return $this->belongsToMany('Role')->withTimestamps();

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSriramanView Question on Stackoverflow
Solution 1 - LaravelmarcanuyView Answer on Stackoverflow