table = $table; } public function select(array $fields = []): self { $allowFields = ['id', 'title', 'created_at',]; $select = $this->getSelectSection($fields, $allowFields, $this->table); $this->queryBuilder = DB::table($this->table); $this->queryBuilder->select($select); return $this; } public function whereId(string $id): self { $this->queryBuilder->where($this->table . '.id', '=', $id); return $this; } public function limit(int $limit, int $offset): self { $this->queryBuilder->limit($limit)->offset($offset); return $this; } public function all(): array { $result = []; foreach ($this->queryBuilder->get()->all() as $row) { $result[$row->id] = $row; } return json_decode(json_encode($result), true); } public function one(): array { $result = $this->queryBuilder->first() ?? []; $result = json_decode(json_encode($result), true); return $result; } }