From dbf373717063ba356226261dc55870227b58de7e Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 27 Sep 2020 23:42:39 +0200 Subject: [PATCH] Questions: Add current timestamp on migration --- ...020_09_27_000000_add_timestamps_to_questions.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/db/migrations/2020_09_27_000000_add_timestamps_to_questions.php b/db/migrations/2020_09_27_000000_add_timestamps_to_questions.php index 6f751a7c..0114bfde 100644 --- a/db/migrations/2020_09_27_000000_add_timestamps_to_questions.php +++ b/db/migrations/2020_09_27_000000_add_timestamps_to_questions.php @@ -2,7 +2,9 @@ namespace Engelsystem\Migrations; +use Carbon\Carbon; use Engelsystem\Database\Migration\Migration; +use Engelsystem\Models\Question; use Illuminate\Database\Schema\Blueprint; class AddTimestampsToQuestions extends Migration @@ -18,6 +20,17 @@ class AddTimestampsToQuestions extends Migration $table->timestamp('answered_at')->after('answerer_id')->nullable(); $table->timestamps(); }); + + $now = Carbon::now(); + Question::query()->update([ + 'created_at' => $now, + 'updated_at' => $now, + ]); + Question::query() + ->whereNotNull('answerer_id') + ->update([ + 'answered_at' => $now, + ]); } /**