Didn't see this as a suggestion already, but it seems silly that in order to set the timestamps columns to default to the current time, you have to specify each column separately in your migration
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
Since the timestamps method creates both of those columns, and it is very common that both would be set to the current time by default, why can't we call useCurrent on it like so?
$table->timestamps()->useCurrent();
or... actually differentiate between nullableTimestamps()
and timestamps()
in the Illuminate\Database\Schema\Blueprint as follows:
/**
* Add nullable creation and update timestamps to the table.
*
* @return void
*/
public function nullableTimestamps()
{
$this->timestamp('created_at')->nullable();
$this->timestamp('updated_at')->nullable();
}
/**
* Add creation and update timestamps to the table defaulting to Current Time.
*
* @return void
*/
public function timestamps()
{
$this->timestamp('created_at')->useCurrent();
$this->timestamp('updated_at')->useCurrent();
}
Making difference again between timestamps
and nullableTimestamps
will make confusion. And adding userCurrent
might have unexpected side effects. In case you don't have your DB server datetime synchronized to your PHP server, when you will use in query some comparison you might get very unexpected results, do in my opinion it's better to use current wasy of using timestamps
and it's not confusing to have two methods with no difference in function where one specifically says nullable? having nullableSomething
and something
implies one is nullable, and one isn't. I don't agree that it's intuitive that they do the same thing.
Closing since it's not actually a bug report, but please feel free to continue discussion in the internals repo https://github.com/laravel/internals
Most helpful comment
and it's not confusing to have two methods with no difference in function where one specifically says nullable? having
nullableSomething
andsomething
implies one is nullable, and one isn't. I don't agree that it's intuitive that they do the same thing.