36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Seeds;
|
|
|
|
use CodeIgniter\Database\Seeder;
|
|
|
|
class AuthSeeder extends Seeder
|
|
{
|
|
public function run()
|
|
{
|
|
$roles = [
|
|
['role_code' => 'ADMIN', 'role_name' => 'Administrator'],
|
|
['role_code' => 'WALI_KELAS', 'role_name' => 'Wali Kelas'],
|
|
['role_code' => 'GURU_BK', 'role_name' => 'Guru BK'],
|
|
['role_code' => 'GURU_MAPEL', 'role_name' => 'Guru Mata Pelajaran'],
|
|
['role_code' => 'ORANG_TUA', 'role_name' => 'Orang Tua'],
|
|
];
|
|
$this->db->table('roles')->insertBatch($roles);
|
|
|
|
$this->db->table('users')->insert([
|
|
'name' => 'Admin',
|
|
'email' => 'admin@example.com',
|
|
'password_hash' => password_hash('admin123', PASSWORD_DEFAULT),
|
|
'is_active' => 1,
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
$adminId = $this->db->insertID();
|
|
$adminRoleId = $this->db->table('roles')->where('role_code', 'ADMIN')->get()->getRow()->id;
|
|
$this->db->table('user_roles')->insert([
|
|
'user_id' => $adminId,
|
|
'role_id' => $adminRoleId,
|
|
]);
|
|
}
|
|
}
|