diff --git a/app/Enums/RoleEnum.php b/app/Enums/RoleEnum.php new file mode 100644 index 0000000..1cea689 --- /dev/null +++ b/app/Enums/RoleEnum.php @@ -0,0 +1,22 @@ +mapWithKeys(fn ($case) => [$case->value => $case->value]) + ->toArray(); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 749c7b7..f858a3a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,46 +2,24 @@ namespace App\Models; -// use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { - /** @use HasFactory<\Database\Factories\UserFactory> */ - use HasFactory, Notifiable; + use HasFactory, Notifiable, SoftDeletes; - /** - * The attributes that are mass assignable. - * - * @var list - */ - protected $fillable = [ - 'name', - 'email', - 'password', - ]; + protected $guarded = ['id']; - /** - * The attributes that should be hidden for serialization. - * - * @var list - */ protected $hidden = [ 'password', - 'remember_token', ]; - /** - * Get the attributes that should be cast. - * - * @return array - */ protected function casts(): array { return [ - 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } diff --git a/app/Traits/Enum/WithComment.php b/app/Traits/Enum/WithComment.php new file mode 100644 index 0000000..9affe15 --- /dev/null +++ b/app/Traits/Enum/WithComment.php @@ -0,0 +1,11 @@ + "{$case->value}: {$case->getLabel()}", self::cases())); + } +} diff --git a/app/Traits/Enum/WithValue.php b/app/Traits/Enum/WithValue.php new file mode 100644 index 0000000..47d3487 --- /dev/null +++ b/app/Traits/Enum/WithValue.php @@ -0,0 +1,11 @@ + $case->value, self::cases()); + } +} diff --git a/config/auth.php b/config/auth.php index 7d1eb0d..e791126 100644 --- a/config/auth.php +++ b/config/auth.php @@ -112,4 +112,5 @@ 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), + 'password_default' => env('PASSWORD_DEFAULT', 'users'), ]; diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 05fb5d9..00a7cf4 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -13,12 +13,13 @@ public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); + $table->string('name', 100); + $table->string('email', 254)->unique(); + $table->string('username', 10)->unique(); + $table->string('password', 60); + $table->timestamp('created_at')->useCurrent(); + $table->timestamp('updated_at')->nullable()->useCurrentOnUpdate(); + $table->softDeletes(); }); Schema::create('password_reset_tokens', function (Blueprint $table) { diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6b901f8..b9c7377 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -2,7 +2,6 @@ namespace Database\Seeders; -use App\Models\User; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; @@ -15,11 +14,8 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // User::factory(10)->create(); - - User::factory()->create([ - 'name' => 'Test User', - 'email' => 'test@example.com', + $this->call([ + UserSeeder::class, ]); } } diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php new file mode 100644 index 0000000..f252a25 --- /dev/null +++ b/database/seeders/UserSeeder.php @@ -0,0 +1,40 @@ + 'Yoga Pangestu', + 'email' => 'info.pangestuyoga@gmail.com', + 'username' => 'pangestu', + 'password' => Hash::make(config('auth.password_default')), + ]); + + // owner + $owner = User::create([ + 'name' => 'Owner', + 'email' => 'owner@gmail.com', + 'username' => 'owner', + 'password' => Hash::make(config('auth.password_default')), + ]); + + // admin + $administrator = User::create([ + 'name' => 'Administrator', + 'email' => 'admin@gmail.com', + 'username' => 'admin', + 'password' => Hash::make(config('auth.password_default')), + ]); + } +}