Skip to content

Commit

Permalink
generate student id number when it is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
iqbaleff214 committed Jun 4, 2024
1 parent 3e18c37 commit 3910252
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/Models/Student.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ protected static function boot(): void
parent::boot();
static::creating(function (Student $student) {
if (is_null($student->student_id_number)) {
$student->student_id_number = time().random_int(0, 1000).time();
$studentIdNumber = $student->gender === 'male' ? 'I' : 'A';
$studentIdNumber .= now()->toHijri()->isoFormat('YYMM');
$number = Student::where('student_id_number', 'LIKE', $studentIdNumber . '%')->count() + 1;
$student->student_id_number = $studentIdNumber . str_pad($number, 3, '0',STR_PAD_LEFT);
}
});
static::deleting(function (Student $student) {
Expand Down

0 comments on commit 3910252

Please sign in to comment.