57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\BaseModel;
|
|
|
|
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();
|
|
}
|
|
} |