Skip to content

Commit abd06fb

Browse files
authored
Merge pull request #263 from laravel-enso/feature/nestedColumnsFormatting
implements number and date formating for nested columns from loaded relationships
2 parents 0325825 + cd3e0d3 commit abd06fb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Services/Data/Computors/Date.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace LaravelEnso\Tables\Services\Data\Computors;
44

55
use Carbon\Carbon;
6+
use Illuminate\Support\Arr;
67
use Illuminate\Support\Facades\Config;
78
use LaravelEnso\Helpers\Services\Obj;
89
use LaravelEnso\Tables\Contracts\ComputesArrayColumns;
@@ -21,10 +22,11 @@ public static function columns($columns): void
2122
public static function handle(array $row): array
2223
{
2324
foreach (self::$columns as $column) {
24-
if ($row[$column->get('name')] !== null) {
25-
$row[$column->get('name')] = Carbon::parse($row[$column->get('name')])
25+
$rowValue = Arr::get($row, $column->get('name'));
26+
if ($rowValue !== null) {
27+
Arr::set($row, $column->get('name'), Carbon::parse($rowValue)
2628
->setTimezone(Config::get('app.timezone'))
27-
->format(self::format($column));
29+
->format(self::format($column)));
2830
}
2931
}
3032

src/Services/Data/Computors/Number.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace LaravelEnso\Tables\Services\Data\Computors;
44

5+
use Illuminate\Support\Arr;
56
use Illuminate\Support\Facades\App;
67
use LaravelEnso\Helpers\Services\Obj;
78
use LaravelEnso\Tables\Contracts\ComputesArrayColumns;
@@ -22,10 +23,10 @@ public static function columns($columns): void
2223
public static function handle(array $row): array
2324
{
2425
foreach (self::$columns as $column) {
25-
$row[$column->get('name')] = self::format(
26-
$row[$column->get('name')],
26+
Arr::set($row, $column->get('name'), self::format(
27+
Arr::get($row, $column->get('name')),
2728
$column->get('number')->get('precision')
28-
);
29+
));
2930
}
3031

3132
return $row;

0 commit comments

Comments
 (0)