Disable Laravel's Eloquent timestamps

Disable Laravel's Eloquent timestamps

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

Stefan Bogdanescu

Founder & Senior Architect

Disable Laravel's Eloquent Timestamps Without Modifying Core Files

When migrating from a legacy framework like CodeIgniter to Laravel, the temptation to apply every default behavior immediately is strong. However, you might find yourself in a position where Laravel's automatic created_at and updated_at columns conflict with existing logging mechanisms or custom audit trails. You are aware that setting $timestamps = false inside your model class works, but doing this on every single model feels repetitive. Worse still, editing vendor/.../Illuminate/Database/Eloquent/Model.php to disable timestamps globally is a fragile approach that breaks under Composer updates.

The good news is that you do not need to touch core files or duplicate code across your application. Laravel provides a cleaner, more maintainable solution via the config/database.php file.

Global Configuration Override

Laravel allows you to override Eloquent model defaults globally through the database configuration file located at config/database.php. Instead of editing individual models, you can define a global default for the $timestamps property within the migrations or directly in the default array depending on your Laravel version and schema migration strategy.

However, the most robust and standard way to handle this without touching core files is to use the Model class's boot method or a service provider to set a default value for the $timestamps property globally before any model is instantiated. But wait, there is an even simpler approach that requires no code changes at all if you are willing to accept a slight configuration nuance.

Actually, the most direct path without modifying core files involves using a trait or a base model class, but since you want it for all models (including those you haven't created yet), we need to look at how Laravel initializes models.

The reality is that there is no single configuration switch in config/database.php named timestamps = false. The documentation and common practice suggest using a base trait or modifying the boot process. However, if you strictly want to disable it for all existing models without touching each one individually, you must rely on inheritance.

Create a new class file at app/Models/BaseModel.php (or similar) that extends Illuminate\Database\Eloquent\Model. In this class, define $timestamps = false;. Then, in your migration files, set the default model for your connection to extend this base class if possible, or simply have all your models inherit from it.

Wait, Laravel does not allow you to change the default base class globally via config without modifying the core Model class itself. Therefore, the "no core file modification" constraint technically forces you into one of three paths:

  1. Traits: Create a trait App\Traits\NoTimestamps with $timestamps = false;. Then use use App\Traits\NoTimestamps; in every model. This is verbose but safe from updates.
  2. Base Model Inheritance: Create an abstract base class that extends Illuminate\Database\Eloquent\Model and sets $timestamps = false. Then, refactor your existing models to extend this new base class instead of Model directly. Future models should also extend this base class.
  3. Service Provider Boot Method: You cannot set a static property $timestamps in a service provider's boot method because it happens after the class is already defined and resolved.

Given these constraints, the most maintainable solution that adheres to your requirement of not touching core files is creating an abstract base model.

Implementing a Base Model Class

Here is how you can structure your application to enforce this behavior globally:

  1. Create a new file at app/Models/BaseModel.php.
  2. Define the $timestamps property as false.
  3. Ensure all your existing models extend this base class.
// app/Models/BaseModel.php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

abstract class BaseModel extends Model
{
    public $timestamps = false;
}

Now, update your migration classes to use this base model if you are using the Schema builder directly, but note that migrations define the table structure, not the model class. The model class is separate.

For existing models, you can refactor them:

// app/Models/User.php
namespace App\Models;

class User extends BaseModel // Changed from Model to BaseModel
{
    // ...
}

For new models created in the future, simply ensure they extend BaseModel.

Why Not Just Edit Core Files?

You mentioned wanting to avoid editing Vendor\laravel\framework\src\illuminate\Datebase\Eloquent\Model.php. This is crucial advice. Modifying files inside the vendor directory is generally considered an anti-pattern in modern PHP development because:

  • Composer Updates: When you run composer update, Laravel will overwrite your modified core files, reverting your changes to $timestamps = true;. Your application will suddenly start tracking timestamps, potentially breaking your logging logic or data integrity.
  • Supportability: If you ever need help from a community member or an LSP (Laravel Support), they assume the default behavior unless you explicitly state you have patched core files.

The Trade-Offs

Disabling automatic timestamps is not without its costs. By removing Laravel's built-in created_at and updated_at, you lose:

  • Built-in Audit Trails: You lose the immediate ability to see when a record was created or last modified without querying extra columns.
  • Soft Deletes Safety: Some soft delete implementations rely on timestamps for ordering or logic, though this is rare.
  • Database Indexing: Laravel often suggests indexing these columns for performance in filtering queries. If you are handling this manually via your logging class, ensure your custom logging solution creates necessary indexes to prevent query bottlenecks.

Since your application already has a logging class that handles this in more depth, the trade-off is acceptable. However, ensure that logging happens on every relevant mutation (update/create) consistently. Relying solely on a separate logging class while disabling timestamps means you must trust that external logic runs perfectly every time. If an exception occurs during your custom logging step before it writes to the log, the row might get created without a timestamp or with inconsistent data if other parts of the app expect those columns to exist.

Conclusion

To disable Eloquent timestamps globally without modifying core files, creating an abstract base model is the standard, safe approach. It keeps your application upgrade-safe and avoids repetitive code in every model file. While editing the core Model.php works temporarily, it introduces significant risk during dependency updates. By moving the configuration to a dedicated base class, you maintain control over your data schema while adhering to Laravel's architecture.

Our network