- Pasang laravel/sanctum, routes/api.php (prefix api/v1, 10 endpoint) - Migrasi: parent_name di students, parent_students (pivot wali↔anak), parent_devices (token FCM), permission parents-verify - Auth wali: registrasi NISN+HP (auto-verify jika HP cocok data siswa, pending jika tidak) + login token Sanctum - Endpoint: me, logout, students, link anak, violations, sp-letters, notifications, register device - Halaman admin Verifikasi Wali (approve/reject) + menu sidebar - Sync kesiswaan: tarik data orang tua (student_parents) ke students - 8 feature test baru (ParentApiTest) — total suite 39 test hijau
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Student extends Model
|
|
{
|
|
protected $fillable = [
|
|
'source_id', 'nisn', 'student_number', 'full_name',
|
|
'gender', 'place_of_birth', 'date_of_birth', 'address',
|
|
'phone_number', 'parent_phone', 'parent_name', 'email', 'class_name', 'class_level',
|
|
'department_code', 'department_name', 'academic_year_name',
|
|
'status', 'photo_path', 'class_id', 'is_active',
|
|
'metadata', 'synced_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'date_of_birth' => 'date',
|
|
'is_active' => 'boolean',
|
|
'metadata' => 'json',
|
|
'synced_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function violations(): HasMany
|
|
{
|
|
return $this->hasMany(Violation::class);
|
|
}
|
|
|
|
public function spLetters(): HasMany
|
|
{
|
|
return $this->hasMany(SpLetter::class);
|
|
}
|
|
|
|
public function class()
|
|
{
|
|
return $this->belongsTo(Classes::class, 'class_id');
|
|
}
|
|
|
|
public function parentLinks()
|
|
{
|
|
return $this->hasMany(\App\Models\ParentStudent::class, 'student_id');
|
|
}
|
|
|
|
public function getTotalPointsAttribute(): int
|
|
{
|
|
return $this->violations()
|
|
->whereNull('deleted_at')
|
|
->sum('points');
|
|
}
|
|
}
|