This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccount/app/Data/Repository/AppRepository.php
2019-12-02 14:26:32 +01:00

48 lines
977 B
PHP

<?php
namespace App\Data\Repository;
use App\Data\Entity\App;
class AppRepository extends BaseRepository {
protected $table = "apps";
public function getAllApps() {
$pdo = app('db')->getPdo();
$sql = "SELECT * FROM apps;";
$sth = $pdo->prepare($sql);
$sth->execute();
$res = $sth->fetchAll(\PDO::FETCH_ASSOC);
$appList = [];
foreach ($res as $dbEntry) {
$app = new App();
$app->load($dbEntry);
$appList[] = $app;
}
return collect($appList);
}
public function findById($id): ?App {
$pdo = app('db')->getPdo();
$sql = "SELECT * FROM apps WHERE `id` = :id;";
$sth = $pdo->prepare($sql);
$sth->execute([":id" => $id]);
$res = $sth->fetch(\PDO::FETCH_ASSOC);
if(is_null($res)) {
return null;
}
$app = new App();
$app->load($res);
return $app;
}
}