Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Json Output for Collections #12

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,17 @@ public function toJson() {
}, $this->data);
}

/**
* Returns the elements in the $this->data property as an array.
*
* @return array The array containing the converted elements from $this->data.
*/
public function toArray() {
$array = [];
foreach ($this->data as $item) {
$array[] = $item->toArray();
}
return $array;
}

}
16 changes: 12 additions & 4 deletions src/Utils/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ public static function prepareFile(array $params) {
if(!isset($params['image']) && !isset($params['file'])) {
return false;
}
if($other_params = array_diff_key($params, array_flip(['image', 'file']))) {
$other_params = array_map(function ($key) use($other_params){
return [
'name' => $key,
'contents' => $other_params[$key]
];
}, array_keys($other_params));
}
$type = isset($params['image']) ? 'image' : 'file';
return [
[
return array_merge($other_params ?? [],
[[
'name' => $type,
'contents' => fopen($params[$type], 'r')
]
];
]]
);
}

/**
Expand Down