*/ use HasFactory, Notifiable, SoftDeletes; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'email', 'password', 'status', 'role_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', ]; } public function announcements() { return $this->belongsToMany(Announcement::class, 'announcements_users', 'user_id', 'announcement_id') ->using(AnnouncementUser::class) ->withPivot(['status', 'category']) ->withTimestamps(); } public function role(){ return $this->belongsTo(Role::class, 'role_id', 'id'); } public function company(){ return $this->hasOne(Company::class, 'user_id', 'id')->withTrashed(); } public function media() { return $this->hasOneThrough( Media::class, // Model tujuan Company::class, // Model perantara 'user_id', // foreign key di company yang nyambung ke user 'company_id', // foreign key di media yang nyambung ke company 'id', // local key di user 'id' // local key di company ); } public function loginHistories(){ return $this->hasMany(LoginHistory::class, 'user_id', 'id'); } }