feat(usermanagement): optimalkan pencarian dan tambahkan UserFactory

- Ubah pencarian pada `PermissionsController` dan `UsersController`:
  - Gunakan metode `whereRaw` dengan `LOWER` untuk pencocokan case-insensitive pada kolom `name` dan `email`.
- Tambahkan `HasFactory` pada model `User` agar mendukung pembuatan data dummy menggunakan factory.
- Implementasi fungsi `newFactory()` pada model `User` untuk merujuk ke UserFactory.
- Tambahkan file factory baru (`UserFactory`) untuk model `User`:
  - Definisikan state default seperti `name`, `email`, `password`, dan `nik` untuk keperluan pembuatan data dummy.
  - Gunakan password secara default terenkripsi dengan `bcrypt`.
This commit is contained in:
Daeng Deni Mardaeni
2025-05-17 14:12:25 +07:00
parent 33fe30b443
commit 1007515faa
4 changed files with 49 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
namespace Modules\Usermanagement\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@@ -24,7 +25,7 @@
*/
class User extends Authenticatable
{
use Notifiable, Userstamps, HasRoles, softDeletes;
use HasFactory, Notifiable, Userstamps, HasRoles, softDeletes;
protected $guard_name = ['web'];
@@ -80,5 +81,14 @@
public function branch(){
return $this->belongsTo(Branch::class);
}
}
/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
protected static function newFactory()
{
return \Modules\Usermanagement\Database\Factories\UserFactory::new();
}
}