2026-05-30 22:15:16 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
|
{
|
|
|
|
|
use HasFactory, Notifiable, HasRoles;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
* Kolom-kolom ini wajib didaftarkan agar form Create & Edit tidak diblokir Laravel.
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'nik',
|
|
|
|
|
'identity_number',
|
|
|
|
|
'initial',
|
|
|
|
|
'first_name',
|
|
|
|
|
'last_name',
|
|
|
|
|
'phone',
|
|
|
|
|
'email',
|
|
|
|
|
'password',
|
|
|
|
|
'role',
|
|
|
|
|
'gender',
|
|
|
|
|
'date_of_birth',
|
|
|
|
|
'join_date',
|
|
|
|
|
'photo',
|
|
|
|
|
'department_id',
|
|
|
|
|
'position_id',
|
|
|
|
|
'training_matrix_id',
|
|
|
|
|
'old_id',
|
|
|
|
|
'old_password_hash',
|
|
|
|
|
'is_active',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be hidden for serialization.
|
|
|
|
|
*/
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'password',
|
|
|
|
|
'remember_token',
|
|
|
|
|
'old_password_hash',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mengubah format string dari database menjadi format Date/Time Carbon otomatis.
|
|
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
|
'password' => 'hashed',
|
|
|
|
|
'date_of_birth' => 'date',
|
|
|
|
|
'join_date' => 'date',
|
|
|
|
|
'is_active' => 'boolean',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// =========================================================================
|
|
|
|
|
// RELASI ANTAR TABEL (MASTER DATA)
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
|
|
// Relasi ke tabel departments
|
|
|
|
|
public function department()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Department::class, 'department_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Relasi ke tabel positions
|
|
|
|
|
public function position()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Position::class, 'position_id');
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-05 13:39:13 +07:00
|
|
|
public function subjects()
|
|
|
|
|
{
|
|
|
|
|
// Parameter ke-3 'user_id' akan memaksa Laravel mengabaikan pencarian 'employee_id'
|
|
|
|
|
return $this->belongsToMany(\App\Models\Subject::class, 'employee_subject', 'user_id', 'subject_id')
|
|
|
|
|
->withPivot('status')
|
|
|
|
|
->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-04 19:01:17 +07:00
|
|
|
public function trainings()
|
2026-05-30 22:15:16 +07:00
|
|
|
{
|
2026-06-05 13:39:13 +07:00
|
|
|
// Karena ini Model User, foreign key-nya harus 'user_id'
|
|
|
|
|
return $this->belongsToMany(Subject::class, 'employee_subject', 'user_id', 'subject_id')
|
2026-06-04 19:01:17 +07:00
|
|
|
->withPivot('status')
|
|
|
|
|
->withTimestamps();
|
2026-05-30 22:15:16 +07:00
|
|
|
}
|
2026-06-04 19:01:17 +07:00
|
|
|
|
|
|
|
|
|
2026-05-30 22:15:16 +07:00
|
|
|
}
|