migrant-web/app/Console/Commands/ClearDatabaseData.php
2026-05-20 13:26:43 +05:30

54 lines
1.6 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ClearDatabaseData extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:clear-data';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear active database data tables for manual testing, preserving authentication and categories';
/**
* Execute the console command.
*/
public function handle()
{
$this->info('Clearing database tables...');
Schema::disableForeignKeyConstraints();
// Truncate recruitment, dynamic, and worker tables
DB::table('shortlists')->truncate();
DB::table('job_applications')->truncate();
DB::table('job_posts')->truncate();
DB::table('messages')->truncate();
DB::table('conversations')->truncate();
DB::table('announcements')->truncate();
DB::table('worker_documents')->truncate();
DB::table('worker_skills')->truncate();
DB::table('workers')->truncate();
// Also delete non-seeded users if any (keep Admin and Employer)
DB::table('users')->whereNotIn('email', ['admin@example.com', 'employer1@example.com'])->delete();
Schema::enableForeignKeyConstraints();
$this->info('Database cleared successfully! You can now register, post jobs, and apply manually.');
return Command::SUCCESS;
}
}