153 lines
3.8 KiB
PHP
153 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Student extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::deleting(function (Student $student) {
|
|
if ($student->isForceDeleting()) {
|
|
$student->documents()->withTrashed()->get()->each->forceDelete();
|
|
$student->parents()->delete();
|
|
$student->academicHistories()->delete();
|
|
|
|
return;
|
|
}
|
|
|
|
$student->documents()->get()->each->delete();
|
|
$student->parents()->delete();
|
|
});
|
|
|
|
static::restoring(function (Student $student) {
|
|
$student->documents()->onlyTrashed()->restore();
|
|
});
|
|
}
|
|
|
|
protected $fillable = [
|
|
'student_number',
|
|
'nisn',
|
|
'full_name',
|
|
'gender',
|
|
'place_of_birth',
|
|
'date_of_birth',
|
|
'religion',
|
|
'nationality',
|
|
'family_card_number',
|
|
'child_order',
|
|
'number_of_siblings',
|
|
'phone_number',
|
|
'email',
|
|
'address',
|
|
'province_id',
|
|
'regency_id',
|
|
'district_id',
|
|
'village_id',
|
|
'village',
|
|
'district',
|
|
'city',
|
|
'province',
|
|
'postal_code',
|
|
'academic_year_id',
|
|
'department_id',
|
|
'class_id',
|
|
'entry_date',
|
|
'status',
|
|
'self_service_status',
|
|
'self_service_last_access_at',
|
|
'self_service_submitted_at',
|
|
'self_service_access_code',
|
|
'self_service_code_generated_at',
|
|
'photo_path',
|
|
'notes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'date_of_birth' => 'date',
|
|
'entry_date' => 'date',
|
|
'self_service_last_access_at' => 'datetime',
|
|
'self_service_submitted_at' => 'datetime',
|
|
'self_service_code_generated_at' => 'datetime',
|
|
'child_order' => 'integer',
|
|
'number_of_siblings' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function academicYear(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AcademicYear::class);
|
|
}
|
|
|
|
public function department(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Department::class);
|
|
}
|
|
|
|
public function classRoom(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SchoolClass::class, 'class_id');
|
|
}
|
|
|
|
public function provinceRef(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Province::class, 'province_id');
|
|
}
|
|
|
|
public function regencyRef(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Regency::class, 'regency_id');
|
|
}
|
|
|
|
public function districtRef(): BelongsTo
|
|
{
|
|
return $this->belongsTo(District::class, 'district_id');
|
|
}
|
|
|
|
public function villageRef(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Village::class, 'village_id');
|
|
}
|
|
|
|
public function parents(): HasMany
|
|
{
|
|
return $this->hasMany(StudentParent::class);
|
|
}
|
|
|
|
public function documents(): HasMany
|
|
{
|
|
return $this->hasMany(StudentDocument::class);
|
|
}
|
|
|
|
public function academicHistories(): HasMany
|
|
{
|
|
return $this->hasMany(StudentAcademicHistory::class)->latest('academic_year_id');
|
|
}
|
|
|
|
public function exitRecord(): HasOne
|
|
{
|
|
return $this->hasOne(StudentExit::class);
|
|
}
|
|
|
|
public function transferRecord(): HasOne
|
|
{
|
|
return $this->hasOne(StudentTransfer::class);
|
|
}
|
|
|
|
public function achievements(): HasMany
|
|
{
|
|
return $this->hasMany(StudentAchievement::class)->latest('achievement_year')->latest('achievement_date');
|
|
}
|
|
}
|