New-OMIS/database/seeders/DatabaseSeeder.php

65 lines
2.2 KiB
PHP
Raw Normal View History

2024-04-04 07:23:00 +00:00
<?php
namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
2024-04-04 16:16:09 +00:00
use Illuminate\Support\Facades\Hash;
2024-04-04 07:23:00 +00:00
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
2024-04-10 12:21:18 +00:00
// \App\Models\User::factory(10)->create();
2024-04-04 07:23:00 +00:00
$admin = \App\Models\User::factory()->create([
'name' => 'Admin User',
'email' => 'admin@gmail.com',
2024-04-10 12:21:18 +00:00
'employee_id' => 1,
'password' => bcrypt('password'),
2024-04-04 16:16:09 +00:00
2024-04-04 07:23:00 +00:00
]);
$member = \App\Models\User::factory()->create([
'name' => 'Member User',
'email' => 'member@gmail.com',
2024-04-10 12:21:18 +00:00
'employee_id' => 2,
'password' => bcrypt('password'),
2024-04-04 16:16:09 +00:00
2024-04-04 07:23:00 +00:00
]);
$adminRole = Role::create(['name' => 'admin']);
$memberRole = Role::create(['name' => 'member']);
2024-04-05 12:11:16 +00:00
$permission = Permission::create(['name' => 'create leaves']);
$permission = Permission::create(['name' => 'access leaves']);
$permission = Permission::create(['name' => 'edit leaves']);
$permission = Permission::create(['name' => 'delete leaves']);
2024-04-04 07:23:00 +00:00
$permission = Permission::create(['name' => 'access roles']);
$permission = Permission::create(['name' => 'edit roles']);
$permission = Permission::create(['name' => 'create roles']);
$permission = Permission::create(['name' => 'delete roles']);
$permission = Permission::create(['name' => 'access users']);
$permission = Permission::create(['name' => 'edit users']);
$permission = Permission::create(['name' => 'create users']);
$permission = Permission::create(['name' => 'delete users']);
$permission = Permission::create(['name' => 'access permissions']);
$permission = Permission::create(['name' => 'edit permissions']);
$permission = Permission::create(['name' => 'create permissions']);
$permission = Permission::create(['name' => 'delete permissions']);
$admin->assignRole($adminRole);
$member->assignRole($memberRole);
$adminRole->givePermissionTo(Permission::all());
}
}