Skip to content

Commit 743850f

Browse files
committed
wip
1 parent 127a5c2 commit 743850f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Enums/Arrayable.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cone\Root\Enums;
6+
7+
trait Arrayable
8+
{
9+
/**
10+
* Get the label of the enum case.
11+
*/
12+
abstract public function label(): string;
13+
14+
/**
15+
* Convert to array.
16+
*/
17+
public static function toArray(): array
18+
{
19+
return array_reduce(self::cases(), function (array $cases, self $case): array {
20+
return array_merge(
21+
$cases,
22+
[$case->value => $case->label()]
23+
);
24+
}, []);
25+
}
26+
}

src/Fields/Repeater.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ public function resolveOptions(Request $request, Model $model): array
191191
{
192192
$value = (array) $this->resolveValue($request, $model);
193193

194-
return array_map(fn (array $option): array => $this->toOption($request, $model, $this->newTemporaryModel($option)), $value);
194+
return array_map(function (array $option) use ($request, $model): array {
195+
return $this->toOption($request, $model, $this->newTemporaryModel($option));
196+
}, $value);
195197
}
196198

197199
/**

0 commit comments

Comments
 (0)