keksAccount/app/Data/Repository/AppRepository.php

49 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;
}
}