Framework: Why not allow UseCurrent to be called on timestamps in migration.

Created on 8 Aug 2016  路  3Comments  路  Source: laravel/framework

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();
    }

Most helpful comment

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.

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

shopblocks picture shopblocks  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

gabriellimo picture gabriellimo  路  3Comments

kerbylav picture kerbylav  路  3Comments