Membuat akun SuperAdmin

This commit is contained in:
2026-06-05 15:39:38 +07:00
parent 35b18f69c7
commit dfff1f18e9
6 changed files with 61 additions and 7 deletions
+4
View File
@@ -63,3 +63,7 @@ AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
SUPERADMIN_NAME="SuperAdmin"
SUPERADMIN_EMAIL="admin@gmail.com"
SUPERADMIN_PASSWORD="password_yang_aman"
+1
View File
@@ -22,6 +22,7 @@ class User extends Authenticatable
'name',
'email',
'password',
'role',
];
/**
+1
View File
@@ -29,6 +29,7 @@ class UserFactory extends Factory
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'role' => 'user',
'remember_token' => Str::random(10),
];
}
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('role')->default('user')->after('password');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('role');
});
}
};
+3 -7
View File
@@ -8,18 +8,14 @@ use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
use WithoutModelEvents;
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
// Memanggil SuperAdminSeeder
$this->call([
SuperAdminSeeder::class,
]);
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
class SuperAdminSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
User::create([
'name' => env('SUPERADMIN_NAME', 'SuperAdmin'),
'email' => env('SUPERADMIN_EMAIL', 'admin@gmail.com'),
'password' => Hash::make(env('SUPERADMIN_PASSWORD', 'qwerty#123')), // Ganti dengan password yang aman
'role' => 'admin', // Menyesuaikan kolom role yang Anda buat di tabel users
]);
}
}