Skip to content

Commit

Permalink
fix bugs on creating addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
eisfeuer committed Oct 15, 2020
1 parent a2a9f9c commit 64b86c5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"Elbgoods\\NovaAddressField\\": "src/"
}
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true,
"scripts": {
"fix": "vendor/bin/php-cs-fixer fix --using-cache=no --config=vendor/elbgoods/ci-test-tools/configs/.php_cs.dist src",
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ export default {
*/
setInitialValue () {
if (typeof this.field.value === 'object') {
this.value = this.field.value
this.value = this.field.value || {}
} else if (typeof this.field.value === 'string') {
this.value = JSON.parse(this.field.value)
} else {
this.value = {}
}
this.value.country_code = 'DE'
},
Expand Down
13 changes: 12 additions & 1 deletion src/NovaAddressField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Elbgoods\NovaAddressField;

use Elbgoods\LaravelAddressable\Models\Address;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Http\Requests\NovaRequest;

Expand Down Expand Up @@ -97,7 +98,17 @@ public function longitude(string $field): self
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute): void
{
if ($request->exists($requestAttribute)) {
$model->{$attribute} = json_decode($request[$requestAttribute], true);
$addressAttribute = $model->{$attribute};
$addressData = json_decode($request[$requestAttribute], true);
if ($addressAttribute instanceof Address) {
$addressAttribute->properties = json_decode($request[$requestAttribute], true);
$addressAttribute->country_code = $addressData['country_code'];
} else {
$model->{$attribute} = [
'properties' => json_decode($request[$requestAttribute], true),
'country_code' => $addressData['country_code'],
];
}
}
}
}

0 comments on commit 64b86c5

Please sign in to comment.