Timestamps (updated_at, created_at) are null in Laravel 5
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Timestamps (updated_at, created_at) are Null in Laravel 5: Troubleshooting and Solutions
When you face problems with timestamps (created_at and updated_at) fields that return null values in your Laravel migration, it can be quite daunting. In this comprehensive blog post, we will explore the reasons behind such issues and provide solutions to help you resolve them.
To begin with, let us understand how timestamps are handled within Laravel migrations. By default, when you use the `timestamps()` function in your migration file:
Schema::create('lots', function (Blueprint $table) {
$table->increments('id');
$table->integer('lot');
$table->integer('is_active');
$table->timestamps();
});
The migration will automatically add two columns to your table: a `created_at` column for the timestamp of record creation and an `updated_at` column for the last time the record was modified. While these fields are created in the migrations, they aren't populated with any values by default. This is where the confusion arises regarding why null timestamps show up when inserting data into your table.
To address this issue and make auto-completion work as you expect:
1. Use `fillable()` in your Eloquent model to define which columns are mass assignable. This will ensure that the mass assignment validation is successful, allowing Laravel to fill timestamps automatically when inserting new records.
protected $fillable = [
'lot',
'is_active'
];
2. Ensure that you are specifying all columns in the `insert()` statement while inserting data, including timestamps:
\DB::table('admin_lots')->insert([
'lot' => $request->cycle_lot,
'is_active' => '1',
'created_at' => \Carbon\Carbon::now(), // Ensure the right date and time are set.
'updated_at' => \Carbon\Carbon::now()
]);
3. If you don't want to explicitly set a value for created_at while inserting, use nullable timestamps in your migration:
Schema::create('lots', function (Blueprint $table) {
$table->increments('id');
$table->integer('lot');
$table->nullableTimestamps(); // This option sets created_at and updated_at as nullable fields.
$table->boolean('is_active');
});
For further clarification, it is essential to understand that `fillable()` specifies the columns that can be mass-assigned during model instantiation, whereas `timestamps()` is used for creating timestamp columns and handling their values in migrations. Using both features together will ensure that your timestamps are filled automatically when inserting data into your Laravel models.
Following these steps should resolve the issue of null timestamps in Laravel 5 and allow you to manage your database more effectively. Remember, proper naming conventions and structure within migrations can save you time and effort down the road. For a comprehensive understanding of this topic, check out our tutorials on Laravel Company's blog (https://laravelcompany.com/blog).