tanggal_masuk)); $birth_date = date('Ymd', strtotime($this->tanggal_lahir)); $gender = $this->attributes['jenis_kelamin']=='L' ? 1 : 2; $last_karyawan_id = Karyawan::count()+1; $increment = str_pad($last_karyawan_id, 4, '0', STR_PAD_LEFT); $this->attributes['nip'] = $year . $birth_date . $gender . $increment; } // boot function to set default value for setting nip attribute protected static function boot() { parent::boot(); static::creating(function ($model) { $model->setNipAttribute(); }); } }