type === 'internship') { $model->username = $model->email; if (!$model->certificate_code) { do { $code = 'TRN-' . date('Y') . '-' . strtoupper(\Illuminate\Support\Str::random(4)) . '-' . strtoupper(\Illuminate\Support\Str::random(4)); } while (static::where('certificate_code', $code)->exists()); $model->certificate_code = $code; } } }); } /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'password' => 'hashed', ]; } }