Change name of Laravel's created_at and updated_at

Change name of Laravel's created_at and updated_at

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Mapping Laravel Timestamps to WordPress Schema Columns

When migrating a legacy application or reading into an existing database, you often encounter a mismatch between your framework's conventions and the reality of the schema. A common scenario arises when working with a WordPress database within a Laravel environment. The posts table contains columns named post_date, post_date_gmt, post_modified, and post_modified_gmt. Meanwhile, Laravel's Eloquent model system is hardcoded to expect created_at and updated_at columns to manage timestamps automatically.

By default, if your model does not explicitly define these timestamps or configure them otherwise, Laravel will attempt to access non-existent columns named created_at and updated_at in the database. This results in a mass assignment exception or simply ignores the automatic timestamp updates, leaving you with inconsistent data integrity. Since the live WordPress database remains in use, you cannot alter the physical schema to rename these columns without risking data loss or breaking the existing application logic.

The solution lies in configuring the Eloquent model to map Laravel's internal expectations to your existing column names. You do this by overriding the $fillable, $dates, and $timestamps properties within your Model class. This approach allows Laravel to function correctly without modifying the underlying database structure, ensuring that post_date is treated as the creation timestamp and post_modified is treated as the update timestamp.

To handle both standard timestamps and their GMT equivalents, you must specify them individually in the $dates property array. Eloquent treats any column listed here as a date or datetime field, automatically casting values to the appropriate format when retrieving data from the database. For instance, if your Post model looks like this:

class Post extends Model
{
    protected $table = 'posts';

    // Define which columns should be treated as timestamps
    protected $dates = [
        'post_date',
        'post_date_gmt',
        'post_modified',
        'post_modified_gmt',
    ];

    // Optional: Disable automatic creation of created_at/updated_at 
    // to prevent Laravel from trying to write to non-existent columns
    public $timestamps = false;

    protected $fillable = [
        'id',
        'post_title',
        'post_content',
        'post_date',
        'post_date_gmt',
        'post_modified',
        'post_modified_gmt',
        // ... other fields
    ];
}

By setting $timestamps to false, you explicitly tell Eloquent not to attempt mass assignment on the default created_at and updated_at columns. This prevents potential errors if those columns do not exist or if their presence conflicts with your specific data model requirements. The $dates array ensures that when you access a $post->post_date, Laravel automatically casts it to a Carbon instance, providing the familiar date methods like format('Y-m-d') or diffForHumans().

This configuration respects the existing data in the database while allowing Laravel to manage the lifecycle of records. When you create a new post via an API or form request, setting $timestamps = false ensures that Laravel does not try to populate missing columns. Instead, your application logic can explicitly set post_date and post_modified if necessary, or rely on the incoming data payload.

One critical consideration is how these dates are stored in the database versus how they appear in memory. If you need to persist changes back to the database, ensure that your mass assignment rules include the columns you intend to update. If you rely on automatic updates, you might need to override the $appends property or use touch() methods carefully, although with $timestamps = false, manual management is often required to keep GMT and local times in sync.

For more complex scenarios involving multiple tables or specific migration strategies, Laravel provides robust tools to handle schema differences without breaking existing applications. If you find yourself needing deeper integration patterns for legacy systems, resources like https://laravelcompany.com offer insights into advanced Eloquent usage and migration best practices.

Our network