Files
alrahma_sunday_school_api/app/Models/SchoolClass.php
T
2026-06-09 01:25:14 -04:00

60 lines
1.2 KiB
PHP

<?php
namespace App\Models;
class SchoolClass extends BaseModel
{
protected $table = 'classes';
// legacy: useTimestamps = false
public $timestamps = false;
protected $fillable = [
'class_name',
'schedule',
'capacity',
'semester',
'school_year',
];
protected $casts = [
'capacity' => 'integer',
];
/* =========================
* legacy method equivalents
* ========================= */
public static function getAllClasses()
{
return static::query()->get();
}
public static function getClassById(int $id): ?self
{
return static::query()->find($id);
}
public static function createClass(array $data): int
{
$row = static::create($data);
return (int) $row->id;
}
public static function updateClass(int $id, array $data): bool
{
return static::query()->whereKey($id)->update($data) >= 0;
}
public static function deleteClass(int $id): bool
{
$row = static::query()->find($id);
if (! $row) {
return false;
}
return (bool) $row->delete();
}
}