Files
alrahma_sunday_school_api/app/Models/PromotionQueue.php
T
2026-03-05 12:29:37 -05:00

45 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use App\Models\BaseModel;
class PromotionQueue extends BaseModel
{
protected $table = 'promotion_queue';
protected $primaryKey = 'id';
protected $fillable = [
'student_id',
'from_class_section_id',
'to_class_id',
'to_class_section_id',
'school_year_from',
'school_year_to',
'status',
'created_at',
'updated_at',
'updated_by',
];
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
public function upsert(array $data): bool
{
if (empty($data['student_id']) || empty($data['school_year_to'])) {
return false;
}
$existing = $this->where('student_id', (int)$data['student_id'])
->where('school_year_to', (string)$data['school_year_to'])
->first();
if ($existing) {
return (bool) $this->update((int)$existing[$this->primaryKey], array_merge($existing, $data));
}
return (bool) $this->insert($data);
}
}