testapi/app/Console/Commands/rmdemodata.php

59 lines
1.4 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use App\Models\SmartdokProfile;
use App\Models\Department;
use App\Models\Project;
use App\Models\WorkHour;
class RmDemoData extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rmdemodata';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Remove all demo data for SmartdokProfile, Department, Project, and WorkHour models';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$this->info('Removing all demo data...');
// Disable foreign key checks for all supported DB drivers
Schema::disableForeignKeyConstraints();
// Truncate pivot tables
DB::table('project_smartdok_profile')->truncate();
DB::table('department_project')->truncate();
// Truncate core tables
WorkHour::truncate();
Project::truncate();
SmartdokProfile::truncate();
Department::truncate();
// Re-enable foreign key checks
Schema::enableForeignKeyConstraints();
$this->info('All demo data removed successfully.');
return 0;
}
}