mardi 18 décembre 2018

How can i set the current_timestamps into last_update column only in timestamps function Laravel 5?

I am using Laravel 5.4, i read the docs said that, there are two function that use really similar name, it's timestamps and timestamp:

Timestamps

$table->timestamps();

Adds nullable created_at and updated_at TIMESTAMP equivalent columns.

Timestamp

$table->timestamp('name_column');

TIMESTAMP equivalent column.

As you can see, timestamps created a default two column, created_at and updated_at with default TIMESTAMP attribute. How could i make only one of the column, which updated_at have CURRENT_TIMESTAMP attribute ?

I have done like below:

$table->timestamps()->useCurrent();

But i got an error instead using above command, so instead i used default(\DB::raw('CURRENT_TIMESTAMP')). To solved this problem, i have to make two command, like below:

$table->timestamp('created_at');
$table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP'));

How could i make that happen ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire