chore: initial Laravel 13 project setup for eCert MBIP
- Laravel 13.9 + PHP 8.5 + MySQL - Bootstrap 5.3 + jQuery 3.7 + Chart.js (replacing Alpine/Tailwind) - Packages: intervention/image, dompdf, simple-qrcode, league/csv, laravel/breeze, laravel/boost - 17 database migrations: users, programs, qr_codes, participants, attendances, certificates, questionnaires, email_logs, audit_logs - 13 Eloquent models with full relationships - Admin layout (Bootstrap 5 sidebar) + public layout (mobile-first) - Rate limiters: checkin (60/min), certificate (30/min) - Admin seeder: admin@mbip.gov.my - Storage directories + symlink configured Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
62
app/Models/Participant.php
Normal file
62
app/Models/Participant.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Participant extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'uuid', 'name', 'no_kp', 'email', 'phone', 'agency', 'participant_type',
|
||||
];
|
||||
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(fn($model) => $model->uuid ??= (string) Str::uuid());
|
||||
}
|
||||
|
||||
public function programs()
|
||||
{
|
||||
return $this->belongsToMany(Program::class, 'program_participants')
|
||||
->withPivot(['registration_source', 'is_pre_registered', 'pre_registered_session', 'status', 'registered_at'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function programParticipants()
|
||||
{
|
||||
return $this->hasMany(ProgramParticipant::class);
|
||||
}
|
||||
|
||||
public function attendances()
|
||||
{
|
||||
return $this->hasMany(Attendance::class);
|
||||
}
|
||||
|
||||
public function certificates()
|
||||
{
|
||||
return $this->hasMany(Certificate::class);
|
||||
}
|
||||
|
||||
public function questionnaireResponses()
|
||||
{
|
||||
return $this->hasMany(QuestionnaireResponse::class);
|
||||
}
|
||||
|
||||
public function attendanceForProgram(int $programId): ?Attendance
|
||||
{
|
||||
return $this->attendances()->where('program_id', $programId)->first();
|
||||
}
|
||||
|
||||
public function hasAnsweredQuestionnaire(int $programId, int $questionnaireSetId): bool
|
||||
{
|
||||
return $this->questionnaireResponses()
|
||||
->where('program_id', $programId)
|
||||
->where('questionnaire_set_id', $questionnaireSetId)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user