If you want to exclude the created_at and updated_at columns from a table and disable them in your Eloquent models, here's how.
To start, ensure you've removed the created_at
and updated_at
columns from your migration.
public function up(): void
{
Schema::create('releases', function (Blueprint $table) {
$table->id();
$table->foreignId('repo_id')->constrained();
$table->string('tag_name');
$table->string('name');
$table->text('body');
// $table->timestamps();
});
}
I've commented it out here for demonstration, but it's best to remove it entirely.
Once you've done that and run your migrations, head to the model you're using and disable timestamps.
class Release extends Model
{
/** @use HasFactory<\Database\Factories\ReleaseFactory> */
use HasFactory;
public $timestamps = false;
}
This ensures that Laravel doesn't fill in the created_at
and updated_at
dates when creating or updating a record.
And that's it! Remove the column, disable with a simple property in your model, and you're done!