Initial commit
This commit is contained in:
33
app/Core/Model.php
Normal file
33
app/Core/Model.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace App\Core;
|
||||
|
||||
abstract class Model {
|
||||
protected static $table;
|
||||
|
||||
protected static function builder() {
|
||||
$pdo = Database::getInstance();
|
||||
return (new QueryBuilder($pdo))->table(static::$table);
|
||||
}
|
||||
|
||||
public static function all() {
|
||||
return self::builder()->get();
|
||||
}
|
||||
|
||||
public static function find($id) {
|
||||
return self::builder()->where('id', $id)->get()[0] ?? null;
|
||||
}
|
||||
public static function create(array $data) {
|
||||
return static::builder()->insert($data);
|
||||
}
|
||||
|
||||
public static function updateById($id, array $data) {
|
||||
return static::builder()->where('id', $id)->update($data);
|
||||
}
|
||||
|
||||
public static function deleteById($id) {
|
||||
return static::builder()->where('id', $id)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user