mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 13:41:23 +00:00
* docs: add CLAUDE.md for Claude Code guidance * fix: handle missing settings table in installation middlewares RedirectIfInstalled crashed with "no such table: settings" when the database_created marker file existed but the database was empty. Changed to use isDbCreated() which verifies actual tables, and added try-catch around Setting queries in both middlewares. * feat: pre-select database driver from env in installation wizard The database step now reads DB_CONNECTION from the environment and pre-selects the matching driver on load, including correct defaults for hostname and port. * feat: pre-select mail driver and config from env in installation wizard The email step now fetches the current mail configuration on load instead of hardcoding the driver to 'mail'. SMTP fields fall back to Laravel config values from the environment. * refactor: remove file-based DB marker in favor of direct DB checks The database_created marker file was a second source of truth that could drift out of sync with the actual database. InstallUtils now checks the database directly via Schema::hasTable which is cached per-request and handles all error cases gracefully.
75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Facades\Hashids;
|
|
use App\Models\Company;
|
|
use App\Models\CompanySetting;
|
|
use App\Models\Customer;
|
|
use App\Models\Setting;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Silber\Bouncer\BouncerFacade;
|
|
|
|
class DemoSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// Create demo user
|
|
$user = User::factory()->create([
|
|
'email' => 'demo@invoiceshelf.com',
|
|
'name' => 'Demo User',
|
|
'role' => 'super admin',
|
|
'password' => 'demo',
|
|
]);
|
|
|
|
// Create demo company
|
|
$company = Company::factory()->create([
|
|
'name' => 'Demo Company',
|
|
'owner_id' => $user->id,
|
|
'slug' => 'demo-company',
|
|
]);
|
|
|
|
$company->unique_hash = Hashids::connection(Company::class)->encode($company->id);
|
|
$company->save();
|
|
$company->setupDefaultData();
|
|
$user->companies()->attach($company->id);
|
|
BouncerFacade::scope()->to($company->id);
|
|
|
|
$user->assign('super admin');
|
|
|
|
// Set default user settings
|
|
$user->setSettings([
|
|
'language' => 'en',
|
|
'timezone' => 'UTC',
|
|
'date_format' => 'DD-MM-YYYY',
|
|
'currency_id' => 1, // USD
|
|
]);
|
|
|
|
// Set company settings
|
|
CompanySetting::setSettings([
|
|
'currency' => 1,
|
|
'date_format' => 'DD-MM-YYYY',
|
|
'language' => 'en',
|
|
'timezone' => 'UTC',
|
|
'fiscal_year' => 'calendar_year',
|
|
'tax_per_item' => false,
|
|
'discount_per_item' => false,
|
|
'invoice_prefix' => 'INV-',
|
|
'estimate_prefix' => 'EST-',
|
|
'payment_prefix' => 'PAY-',
|
|
], $company->id);
|
|
|
|
// Create demo customers
|
|
Customer::factory()->count(5)->create([
|
|
'company_id' => $company->id,
|
|
]);
|
|
|
|
// Mark profile setup as complete
|
|
Setting::setSetting('profile_complete', 'COMPLETED');
|
|
}
|
|
}
|