Files
Investidor-V2/database/seeders/InvestmentAreaSeeder.php
T
nala 67dad461d9
tests / ci (push) Canceled after 0s
provincias
2026-09-29 14:14:06 +02:00

31 lines
1.2 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\Sector;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class InvestmentAreaSeeder extends Seeder
{
public function run(): void
{
DB::transaction(function () {
DB::select('SELECT pg_advisory_xact_lock(290926, 100000)');
foreach (['Turismo', 'Mineração', 'Infra-estruturas', 'Energia', 'Mercado Financeiro', 'Fintech', 'Imobiliário', 'Agronegócio', 'Bens de Consumo e Franquias', 'Tecnologias de Informação'] as $name) {
$key = str_replace('-', '', Str::slug($name));
$exists = Sector::withTrashed()->get(['name'])->contains(fn ($sector) => str_replace('-', '', Str::slug($sector->name)) === $key);
if ($exists) {
continue;
}
$slug = Str::slug($name);
if (Sector::withTrashed()->where('slug', $slug)->exists()) {
$slug .= '-especifica';
}
Sector::create(['name' => $name, 'slug' => $slug, 'is_active' => true, 'sort_order' => 100, 'published_at' => now()]);
}
});
}
}