Skip to content

Commit

Permalink
fix: some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdiunal committed Jul 11, 2024
1 parent cc6da7a commit e1fd5df
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/SettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private function getSettings($name): Collection
)->flatMap(
fn ($setting) => app($setting)->toArray()
);
} catch (RuntimeException|Exception|Error $e) {
} catch (RuntimeException | Exception | Error $e) {
return new Collection([]);
}
}
Expand Down Expand Up @@ -65,30 +65,39 @@ public function __get($name)
return data_get($this->settings, $name, null);
}

protected function all(): Collection
protected function all(bool $dot = true): Collection
{
return collect($this->settings)->when(
! $this->group,
!$this->group,
fn ($collection) => $collection->mapWithKeys(
fn ($setting) => [
$setting::group() => app($setting)->toArray(),
]
)->dot()
)->when(
$dot,
fn ($collection) => $collection->dot()
)
);
}

public function toArray(): array
{
return $this->all()->toArray();
return $this->all(
dot: false
)->toArray();
}

public function toCollection(): Collection
{
return $this->all();
return $this->all(
dot: false
);
}

public function toJson(): string
{
return $this->all()->toJson();
return $this->all(
dot: false
)->toJson();
}
}

0 comments on commit e1fd5df

Please sign in to comment.