I have recently added a new migration to my database which in its simplest form does something like this
If(Schema::hasTable('some_table')){
Schema::table('some_table', function (Blueprint $table) {
$table->dateTime('last_updated')->nullable(false)->useCurrent()->change();
});
}
According to this answer on SE, Laravel should automatically create and updated the last_record column for me but I am testing this in MySQL 5.7.31 and this is definitely not the case for me. I am using Laravel 7.5 and my PHP version is 7.3.21.
Meanwhile, adding CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
manually to my database failed as well. So, it seems that it might be an issue with my MySQL database instead of Laravel itself. So, I have two questions:
Is it possible to somehow use Laravel/PHP to always add a default value to a field when nothing is passed on insert or update?
Edit: @lagbox asked about how I am saving/updating records in my database. Here is how
$record= TableModel::where('blah', $blah)
->first();
if($record){
$record->update([
'blah1' => $blah1,
'blah2' => $blah2
]);
}