From baa60d55c1b934f10f446bf69f3655843587e619 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Sat, 19 Nov 2022 22:09:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E6=97=B6=E8=AE=A1=E8=B4=B9=20?= =?UTF-8?q?=E5=9F=BA=E7=A1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022_11_19_220435_add_hour_to_hosts.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 database/migrations/2022_11_19_220435_add_hour_to_hosts.php diff --git a/database/migrations/2022_11_19_220435_add_hour_to_hosts.php b/database/migrations/2022_11_19_220435_add_hour_to_hosts.php new file mode 100644 index 0000000..35e2e81 --- /dev/null +++ b/database/migrations/2022_11_19_220435_add_hour_to_hosts.php @@ -0,0 +1,43 @@ +tinyInteger('hour')->index()->nullable()->after('status'); + }); + + Host::chunk(100, function ($hosts) { + foreach ($hosts as $host) { + $host->hour = $host->created_at->hour; + $host->save(); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('hosts', function (Blueprint $table) { + // + + $table->dropColumn('hour'); + }); + } +};