56 lines
2.0 KiB
PHP
56 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\License;
|
|
use App\Models\Role;
|
|
use App\Models\Tenant;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class MusterschuleSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$school = Tenant::firstOrCreate(
|
|
['name' => 'Musterschule Wien'],
|
|
['type' => 'school', 'active' => true]
|
|
);
|
|
|
|
$license = License::withoutGlobalScopes()->firstOrCreate(
|
|
['tenant_id' => $school->id, 'type' => 'school_flat'],
|
|
['seats' => null, 'expires_at' => now()->addYear(), 'active' => true]
|
|
);
|
|
|
|
$users = [
|
|
['email' => 'schuladmin@musterschule.at', 'name' => 'Schuladmin Muster', 'role' => 'school-admin'],
|
|
['email' => 'lehrer@musterschule.at', 'name' => 'Lehrerin Muster', 'role' => 'teacher'],
|
|
['email' => 'kind1@musterschule.at', 'name' => 'Kind 1', 'role' => 'child'],
|
|
['email' => 'kind2@musterschule.at', 'name' => 'Kind 2', 'role' => 'child'],
|
|
];
|
|
|
|
foreach ($users as $data) {
|
|
$user = \App\Models\User::withoutGlobalScopes()->firstOrCreate(
|
|
['email' => $data['email']],
|
|
['name' => $data['name'], 'tenant_id' => $school->id, 'password' => Hash::make('password')]
|
|
);
|
|
|
|
$role = Role::where('name', $data['role'])->first();
|
|
DB::table('role_user')->updateOrInsert(
|
|
['user_id' => $user->id],
|
|
['role_id' => $role->id, 'created_at' => now(), 'updated_at' => now()]
|
|
);
|
|
|
|
if ($data['role'] === 'child') {
|
|
DB::table('license_assignments')->insertOrIgnore([
|
|
'license_id' => $license->id,
|
|
'user_id' => $user->id,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|