<?php
|
namespace App\Models;
|
|
use App\Database;
|
use PDO;
|
use Framework\Model;
|
class Product extends Model {
|
//protected ?string $table = "product";
|
|
|
protected function validate(array $data): void {
|
|
if(empty($data["name"])) {
|
$this->addError("name","Name is required");
|
}
|
}
|
|
public function getTotal() : int {
|
$sql = "SELECT COUNT(*) AS total FROM product";
|
$conn = $this->database->getConnection();
|
$stmt = $conn->query($sql);
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
return (int) $row["total"];
|
|
|
}
|
}
|