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

49 lines
977 B
PHP
Raw Permalink Normal View History

2019-12-02 13:26:32 +00:00
<?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;
}
}