56 lines
2.3 KiB
PHP
56 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Modules\ContractorManagement\Models\Contractor;
|
|
|
|
class MainContractorSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Create the main contractor record and link it to the Super Admin user.
|
|
*
|
|
* The Super Admin (superadmin@gsb-cons.com) starts with contractor_id = null
|
|
* (platform owner). This seeder creates "Great SwissMetal Builders Corporation"
|
|
* as a main contractor and links the Super Admin to it so they can access
|
|
* contractor-scoped features (bidding portal, etc.).
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// 1. Create or find the main contractor
|
|
$contractor = Contractor::firstOrCreate(
|
|
['company_name' => 'Great SwissMetal Builders Corporation'],
|
|
[
|
|
'contact_person' => 'Super Administrator',
|
|
'email' => 'info@gsbcorp.com',
|
|
'phone' => null,
|
|
'specialization' => 'General Construction',
|
|
'address' => null,
|
|
'tax_id' => null,
|
|
'payment_terms' => 'Net 30',
|
|
'rating' => 5.0,
|
|
'status' => 'active',
|
|
'type' => 'main',
|
|
'parent_id' => null,
|
|
'user_limit' => 999,
|
|
'shares_materials_catalog' => true,
|
|
]
|
|
);
|
|
|
|
// 2. Link the Super Admin user to this contractor
|
|
$superAdmin = User::where('email', 'superadmin@gsb-cons.com')->first();
|
|
|
|
if ($superAdmin) {
|
|
$superAdmin->update(['contractor_id' => $contractor->id]);
|
|
|
|
$this->command->info("✓ Main contractor created: {$contractor->company_name} (ID: {$contractor->id})");
|
|
$this->command->info("✓ Linked to Super Admin: {$superAdmin->email}");
|
|
} else {
|
|
$this->command->warn('Super Admin user not found — run SuperAdminSeeder first.');
|
|
$this->command->info("✓ Main contractor created: {$contractor->company_name} (ID: {$contractor->id})");
|
|
$this->command->info(" Link manually via Users > Edit > Contractor Link.");
|
|
}
|
|
}
|
|
}
|