42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Seed the application's database.
|
|
*
|
|
* Admin credentials come from the (gitignored) .env so no secret is committed.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// The admin password must be explicit outside local/testing — never silently seed a
|
|
// known credential in production. The dev fallback only applies to local/testing.
|
|
$adminPassword = env('HOMEOS_ADMIN_PASSWORD');
|
|
|
|
if (blank($adminPassword)) {
|
|
if (! app()->environment('local', 'testing')) {
|
|
throw new \RuntimeException('HOMEOS_ADMIN_PASSWORD must be set to seed the admin account outside local/testing.');
|
|
}
|
|
|
|
$adminPassword = 'homeos-dev';
|
|
}
|
|
|
|
User::updateOrCreate(
|
|
['email' => env('HOMEOS_ADMIN_EMAIL', 'admin@homeos.local')],
|
|
[
|
|
'name' => env('HOMEOS_ADMIN_NAME', 'Admin'),
|
|
'password' => Hash::make($adminPassword),
|
|
'email_verified_at' => now(),
|
|
],
|
|
);
|
|
|
|
$this->call(DemoHomeSeeder::class);
|
|
}
|
|
}
|