reconstruction of the project

This commit is contained in:
root
2026-03-08 16:33:24 -04:00
parent 23b7db1107
commit c8de5f7edc
9157 changed files with 77877 additions and 1073823 deletions
+45 -3
View File
@@ -7,7 +7,13 @@ use App\Models\BaseModel;
class Stats extends BaseModel
{
protected $table = 'stats';
protected $primaryKey = 'id';
/**
* If your stats table has created_at/updated_at, keep true (default).
* If it doesn't, set to false.
*/
public $timestamps = false;
protected $fillable = [
'students',
'teachers',
@@ -15,8 +21,44 @@ class Stats extends BaseModel
'users',
];
public function getStats()
protected $casts = [
'students' => 'integer',
'teachers' => 'integer',
'admins' => 'integer',
'users' => 'integer',
];
/**
* CI-compatible: getStats()
* Returns all rows.
*/
public static function getStats()
{
return $this->findAll();
return static::query()->get();
}
/**
* Enhancement: if you treat stats as a single row (common),
* this returns the first row, creating it with zeros if missing.
*/
public static function singleton(): self
{
return static::query()->first() ?? static::query()->create([
'students' => 0,
'teachers' => 0,
'admins' => 0,
'users' => 0,
]);
}
/**
* Enhancement: update singleton stats safely.
*/
public static function updateSingleton(array $data): self
{
$row = static::singleton();
$row->fill($data);
$row->save();
return $row;
}
}