Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested dates format #2271

Open
wants to merge 1 commit into
base: 4.1
Choose a base branch
from

Conversation

alexsmko
Copy link

@alexsmko alexsmko commented Jun 9, 2021

@divine
Copy link
Contributor

divine commented Jun 12, 2021

Hello,

This looks like a breaking change for the projects depending on the old behavior, however, on the other hand, this is definitely a fix.

@Smolevich what do you think?

Thanks!

@@ -216,7 +216,9 @@ public function attributesToArray()
// Convert dot-notation dates.
foreach ($this->getDates() as $key) {
Copy link

@shaedrich shaedrich Jul 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your change works for EmbedsOne but not for EmbedsMany since Arr::has()/Arr::set() doesn't support dot-syntax on nested arrays (entry.*.date). Interestingly, array_get()/array_set() do. So I'd add this to make it work for both EmbedsOne and EmbedsMany:

Suggested change
foreach ($this->getDates() as $key) {
foreach ($this->getDates() as $key) {
$res = data_get($attributes, $key);
if (is_array($res)) {
$res = array_filter($res);
}
if (Str::contains($key, '.') && Arr::has($attributes, $key)) {
Arr::set($attributes, $key, $this->serializeDate(
$this->asDateTime(Arr::get($attributes, $key))
));
} else if (Str::contains($key, '.') && !empty($res)) {
data_set($attributes, $key, $this->serializeDate(
$this->asDateTime(Arr::get($attributes, $key))
));
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants