Skip to content

Commit 2b9230c

Browse files
committed
chore: iterating
1 parent bff23d0 commit 2b9230c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Http/Resources/ApiCollection.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
class ApiCollection extends ResourceCollection
1010
{
1111

12+
/**
13+
* Guard used to retrieve the user from the request.
14+
* null defaults to default guard config (auth.defaults.guard)
15+
*
16+
* @var ?string
17+
*/
18+
protected ?string $guard = null;
19+
20+
public function setGuard(string $guard): static
21+
{
22+
$this->guard = $guard;
23+
24+
return $this;
25+
}
26+
1227
protected ?string $fieldKey = null;
1328

1429
protected function collects()
@@ -31,7 +46,7 @@ public function setFieldKey(?string $fieldKey): static
3146
public function toArray(Request $request)
3247
{
3348
return $this->collection->map(
34-
fn($item) => $item->setFieldKey($this->fieldKey)->toArray($request)
49+
fn($item) => $item->setGuard($this->guard)->setFieldKey($this->fieldKey)->toArray($request)
3550
)->all();
3651
}
3752
}

0 commit comments

Comments
 (0)