siros siros -4 years ago 310
SQL Question

update auto Create_at & Update_at columns at laravel 5.4

here some simple code i have. actuly i was trying to insert some Tag to my database and no problem to that.but once insert my tag "created_at" & "updated_at" columns not update and just NULL
how can i update auto this fields?
i don't have any model
just migration
here my tag migration:

public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->increments('id');
$table->string('tag');
$table->timestamps();
});

Answer Source

Use Eloquent to auto update created_at and updated_at fields.

Model::create($data);
Model::update($data);

When you're using raw queries or query builder, you'll need to update these fields manually.

DB::table('table_name')
  ->insert(['tag' => 'some_tag', 'created_at' => Carbon::now()]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download