小时计费 基础

This commit is contained in:
iVampireSP.com 2022-11-19 22:09:49 +08:00
parent bab3a766f1
commit baa60d55c1
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -0,0 +1,43 @@
<?php
use App\Models\Host;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('hosts', function (Blueprint $table) {
//
$table->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');
});
}
};