0

Hello I'm new in code and I try to change the name columun of created_at and updated_at in User table.

I see other tuto and he write in model : Change name of Laravel's created_at and updated_at

const CREATED_AT = 'post_date';
const UPDATED_AT = 'post_modified';

But for me in User model I write :

class User extends Authenticatable
{
    use Uuid;
    use HasApiTokens,HasFactory, Notifiable;

    const CREATED_AT = 'registered_on';
    const UPDATED_AT = 'modify_on';
}

But when I try the migration the column 'created_at' is here and no the 'registered_on'. Any ideas ?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • That just modifies the name for the Eloquent model, not the actual database or migration. The migration creates those two columns when you use [`->timestamps()`](https://laravel.com/docs/8.x/migrations#column-method-timestamps). You can eliminate that and create your own. – aynber Aug 26 '21 at 15:05

1 Answers1

3

you have just changed the model's column name.

you have to change the migrations too:

remove the ->timestamps() and add the registered_on & modify_on column, like below:

$table->timestamp('registered_on');
$table->timestamp('modify_on');

Note: to remove function is timestamps() with s

Then run:

php artisan migrate:refresh

to rebuild all of the tables

Abilogos
  • 4,777
  • 2
  • 19
  • 39