Skip to content

Commit 1f409fa

Browse files
authored
Add missing logic for attribute name formatting.
1 parent 061f8b7 commit 1f409fa

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/DataProvider.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
namespace Webfox\InertiaDataProviders;
66

7-
use Illuminate\Contracts\Support\Arrayable;
8-
use Illuminate\Contracts\Support\Jsonable;
7+
use ReflectionClass;
98
use Inertia\LazyProp;
109
use Inertia\Response;
11-
use ReflectionClass;
1210
use ReflectionMethod;
13-
use ReflectionNamedType;
1411
use ReflectionProperty;
12+
use ReflectionNamedType;
13+
use Illuminate\Contracts\Support\Jsonable;
1514
use Symfony\Component\VarDumper\VarDumper;
15+
use Illuminate\Contracts\Support\Arrayable;
16+
use Webfox\InertiaDataProviders\AttributeNameFormatters\AttributeNameFormatter;
1617

1718
abstract class DataProvider implements Arrayable, Jsonable
1819
{
@@ -47,7 +48,12 @@ public function toArray(): array
4748
return [$method->name => fn () => app()->call([$this, $method->name])];
4849
});
4950

50-
return collect()->merge($staticData)->merge($convertedProperties)->merge($convertedMethods)->toArray();
51+
return collect()
52+
->merge($staticData)
53+
->merge($convertedProperties)
54+
->merge($convertedMethods)
55+
->mapWithKeys(fn($value, $key) => [$this->attributeNameFormatter()($key) => $value])
56+
->toArray();
5157
}
5258

5359
public function toNestedArray(): array
@@ -75,4 +81,9 @@ public function dd()
7581
$this->dump();
7682
exit(1);
7783
}
84+
85+
protected function attributeNameFormatter(): AttributeNameFormatter
86+
{
87+
return app()->make(config('inertia-dataproviders.attribute_name_formatter'));
88+
}
7889
}

0 commit comments

Comments
 (0)