feat: add app and database modules
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ============================================================
|
||||
*
|
||||
* @project biiproject
|
||||
*
|
||||
* @author Andika Debi Putra
|
||||
*
|
||||
* @email andikadebiputra@gmail.com
|
||||
*
|
||||
* @website https://biiproject.com
|
||||
*
|
||||
* @copyright Copyright (c) 2026 Andika Debi Putra
|
||||
* @license Proprietary - All Rights Reserved
|
||||
*
|
||||
* @version 1.0.0
|
||||
*
|
||||
* @created 2026-05-01
|
||||
* ============================================================
|
||||
*
|
||||
* Unauthorized copying, modification, distribution, or use
|
||||
* of this file is strictly prohibited without prior written
|
||||
* permission from the author.
|
||||
* ============================================================
|
||||
*/
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class AdminUserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Daftar user yang akan dibuat berdasarkan role
|
||||
$users = [
|
||||
[
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin@biiproject.com',
|
||||
'role' => 'Administrator',
|
||||
],
|
||||
[
|
||||
'name' => 'Developer',
|
||||
'email' => 'developer@biiproject.com',
|
||||
'role' => 'Developer',
|
||||
],
|
||||
[
|
||||
'name' => 'User',
|
||||
'email' => 'user@biiproject.com',
|
||||
'role' => 'User',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($users as $userData) {
|
||||
$user = User::updateOrCreate(
|
||||
['email' => $userData['email']],
|
||||
[
|
||||
'name' => $userData['name'],
|
||||
'password' => Hash::make('password'),
|
||||
'email_verified_at' => now(),
|
||||
]
|
||||
);
|
||||
|
||||
// Pastikan role ada sebelum ditugaskan
|
||||
if (Role::where('name', $userData['role'])->exists()) {
|
||||
$user->syncRoles([$userData['role']]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->command->info('All role-based users created successfully with password: password');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user