Skip to content

Commit 94999e1

Browse files
Added serialize method
1 parent 3747cb0 commit 94999e1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Api/Suggest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function last(): ?Suggestion
130130
return $this->all()?->last();
131131
}
132132

133-
public function all(): Collection
133+
public function all(bool $serialize = false): Collection
134134
{
135135
$url_parameter_string = http_build_query($this->url_parameters);
136136
$base_url = $this->getBaseUrl();
@@ -141,7 +141,13 @@ public function all(): Collection
141141
$return = [];
142142

143143
foreach ($data?->suggestions ?? [] as $suggestion) {
144-
$return[] = new Suggestion($suggestion);
144+
$suggest = new Suggestion($suggestion);
145+
146+
if($serialize) {
147+
$suggest = $suggest->serialize();
148+
}
149+
150+
$return[] = $suggest;
145151
}
146152

147153
return collect($return);

src/Models/BaseModel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ public function __call($method, $args = [])
1818
{
1919
return $this?->$method ?? null;
2020
}
21+
22+
public function serialize()
23+
{
24+
return serialize($this);
25+
}
2126
}

0 commit comments

Comments
 (0)