79 lines
2.5 KiB
PHP
79 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Platform\database\seeders;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
use Modules\Company\Models\Company;
|
|
use Modules\Warehouse\app\Models\Warehouse;
|
|
use Modules\Warehouse\app\Models\WarehouseValidationRule;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class PlatformSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Seed the MPBA system tenant and administrator.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$role = Role::findOrCreate('platform-admin', 'web');
|
|
|
|
$company = Company::updateOrCreate(
|
|
['slug' => 'mpba-limited'],
|
|
[
|
|
'uuid' => (string) Str::uuid(),
|
|
'name' => 'MPBA Limited',
|
|
'status' => 'active',
|
|
'timezone' => 'Europe/London',
|
|
'is_system_company' => true,
|
|
'billing_email' => 'mark.gregory@mpba.co.uk',
|
|
],
|
|
);
|
|
|
|
$user = User::updateOrCreate(
|
|
['email' => 'mark.gregory@mpba.co.uk'],
|
|
[
|
|
'company_id' => $company->id,
|
|
'name' => 'Mark Gregory',
|
|
'password' => Hash::make('987400Kmh'),
|
|
'is_platform_admin' => true,
|
|
'is_company_admin' => true,
|
|
'status' => 'active',
|
|
'email_verified_at' => now(),
|
|
],
|
|
);
|
|
$user->assignRole($role);
|
|
$user = User::updateOrCreate(
|
|
['email' => 'david.price@mpba.co.uk'],
|
|
[
|
|
'company_id' => $company->id,
|
|
'name' => 'David Price',
|
|
'password' => Hash::make('Password1'),
|
|
'is_platform_admin' => true,
|
|
'is_company_admin' => true,
|
|
'status' => 'active',
|
|
'email_verified_at' => now(),
|
|
],
|
|
);
|
|
$user->assignRole($role);
|
|
$warehouse = Warehouse::firstOrNew([
|
|
'company_id' => $company->id,
|
|
'code' => 'MPBA-MAIN',
|
|
]);
|
|
|
|
$warehouse->forceFill([
|
|
'uuid' => $warehouse->uuid ?: (string) Str::uuid(),
|
|
'name' => 'MPBA Main Warehouse',
|
|
'status' => 'active',
|
|
'timezone' => 'Europe/London',
|
|
])->save();
|
|
|
|
WarehouseValidationRule::updateOrCreate(
|
|
['warehouse_id' => $warehouse->id, 'rule_key' => 'stock.location.required'],
|
|
['name' => 'Stock location required', 'severity' => 'error', 'is_active' => true, 'configuration' => ['required' => true]],
|
|
);
|
|
}
|
|
}
|