If you want your pivot table to have automatically maintained
created_at and updated_at timestamps, use thewithTimestamps()
method on the relationship definition.
return $this->belongsToMany('Role')->withTimestamps();
- For Laravel 4.2: Working With Pivot Tables
- Laravel 5.0: Working With Pivot Tables
- Laravel 5.1: Retrieving Intermediate Table Columns
- Laravel 5.2: Filtering Relationships Via Intermediate Table Columns
- Laravel 5.3: Filtering Relationships Via Intermediate Table Columns
- Laravel 5.4: Retrieving Intermediate Table Columns
- Laravel 5.5: Retrieving Intermediate Table Columns
- Laravel 5.6: Retrieving Intermediate Table Columns
- Laravel 5.7: Retrieving Intermediate Table Columns
- Laravel 5.8: Retrieving Intermediate Table Columns