commit | author | age
|
15e03a
|
1 |
<?php |
F |
2 |
namespace App\Models; |
|
3 |
|
|
4 |
use App\Database; |
|
5 |
use PDO; |
|
6 |
use Framework\Model; |
|
7 |
class Product extends Model { |
|
8 |
//protected ?string $table = "product"; |
|
9 |
|
|
10 |
|
|
11 |
protected function validate(array $data): void { |
|
12 |
|
|
13 |
if(empty($data["name"])) { |
|
14 |
$this->addError("name","Name is required"); |
|
15 |
} |
|
16 |
} |
|
17 |
|
|
18 |
public function getTotal() : int { |
|
19 |
$sql = "SELECT COUNT(*) AS total FROM product"; |
|
20 |
$conn = $this->database->getConnection(); |
|
21 |
$stmt = $conn->query($sql); |
|
22 |
$row = $stmt->fetch(PDO::FETCH_ASSOC); |
|
23 |
|
|
24 |
return (int) $row["total"]; |
|
25 |
|
|
26 |
|
|
27 |
} |
|
28 |
} |