小时计费 基础
This commit is contained in:
parent
bab3a766f1
commit
baa60d55c1
43
database/migrations/2022_11_19_220435_add_hour_to_hosts.php
Normal file
43
database/migrations/2022_11_19_220435_add_hour_to_hosts.php
Normal 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');
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user