seed for account types
This commit is contained in:
parent
a2bb75fdcc
commit
b574745338
51
database/seeders/AccountTypeSeeder.php
Normal file
51
database/seeders/AccountTypeSeeder.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\AccountType;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AccountTypeSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$now = now();
|
||||
|
||||
// If table is empty, insert with explicit IDs so id=1 exists (matches default logic elsewhere)
|
||||
if (AccountType::count() === 0) {
|
||||
$rows = [
|
||||
['id' => 1, 'name' => 'Default', 'description' => 'Default account type', 'created_at' => $now, 'updated_at' => $now],
|
||||
['id' => 2, 'name' => 'Primary', 'description' => 'Primary account', 'created_at' => $now, 'updated_at' => $now],
|
||||
['id' => 3, 'name' => 'Secondary', 'description' => 'Secondary account', 'created_at' => $now, 'updated_at' => $now],
|
||||
['id' => 4, 'name' => 'Savings', 'description' => 'Savings account', 'created_at' => $now, 'updated_at' => $now],
|
||||
['id' => 5, 'name' => 'Checking', 'description' => 'Checking account', 'created_at' => $now, 'updated_at' => $now],
|
||||
['id' => 6, 'name' => 'Credit', 'description' => 'Credit account', 'created_at' => $now, 'updated_at' => $now],
|
||||
['id' => 7, 'name' => 'Loan', 'description' => 'Loan account', 'created_at' => $now, 'updated_at' => $now],
|
||||
['id' => 8, 'name' => 'Other', 'description' => 'Other account type', 'created_at' => $now, 'updated_at' => $now],
|
||||
];
|
||||
DB::table('account_types')->insert($rows);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If table already has data, ensure the basics exist (idempotent, no explicit IDs)
|
||||
$names = [
|
||||
'Default' => 'Default account type',
|
||||
'Primary' => 'Primary account',
|
||||
'Secondary' => 'Secondary account',
|
||||
'Savings' => 'Savings account',
|
||||
'Checking' => 'Checking account',
|
||||
'Credit' => 'Credit account',
|
||||
'Loan' => 'Loan account',
|
||||
'Other' => 'Other account type',
|
||||
];
|
||||
|
||||
foreach ($names as $name => $desc) {
|
||||
AccountType::updateOrCreate(
|
||||
['name' => $name],
|
||||
['description' => $desc]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user