diff --git a/app/Http/Controllers/AddressController.php b/app/Http/Controllers/AddressController.php
new file mode 100644
index 0000000..7095f6e
--- /dev/null
+++ b/app/Http/Controllers/AddressController.php
@@ -0,0 +1,18 @@
+ $address]);
+ }
+}
diff --git a/app/Http/Controllers/Api/AddressController.php b/app/Http/Controllers/Api/AddressController.php
index b66b45e..4c687e5 100644
--- a/app/Http/Controllers/Api/AddressController.php
+++ b/app/Http/Controllers/Api/AddressController.php
@@ -43,6 +43,7 @@ class AddressController extends Controller
}
$address = $customer->addresses()->create($addressData);
+
return response()->json($address);
}
@@ -54,6 +55,29 @@ class AddressController extends Controller
return response()->json($address);
}
+ /**
+ * Update the specified resource in storage.
+ */
+ public function update(Request $request, Address $address): JsonResponse
+ {
+ $customer = $address->customer;
+ $addressData = $request->validate([
+ 'is_address' => 'boolean',
+ 'is_delivery' => 'boolean',
+ ]);
+
+ if (isset($addressData['is_address']) && $addressData['is_address'] == 1) {
+ $customer->addresses()->where('is_address', true)->update(['is_address' => false]);
+ }
+
+ if (isset($addressData['is_delivery']) && $addressData['is_delivery'] == 1) {
+ $customer->addresses()->where('is_delivery', true)->update(['is_delivery' => false]);
+ }
+ $address->update($addressData);
+
+ return response()->json($address);
+ }
+
/**
* Remove the specified resource from storage.
*/
diff --git a/app/Models/Address.php b/app/Models/Address.php
index c95e131..daa01ca 100644
--- a/app/Models/Address.php
+++ b/app/Models/Address.php
@@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Address extends Model
@@ -26,4 +27,12 @@ class Address extends Model
'country',
'zip',
];
+
+ /**
+ * Return the customer having the address.
+ */
+ public function customer(): BelongsTo
+ {
+ return $this->belongsTo(Customer::class);
+ }
}
diff --git a/lang/de/customer.php b/lang/de/customer.php
index 596d3c8..9489027 100644
--- a/lang/de/customer.php
+++ b/lang/de/customer.php
@@ -15,6 +15,8 @@ return [
'Customer' => 'Kunde',
'Add new customer' => 'Neuer Kunde',
'Edit existing customer' => 'Bestehenden Kunden bearbeiten',
+ 'Edit existing address' => 'Bestehende Adresse bearbeiten',
+ 'Edit existing addresses' => 'Bestehende Adresse bearbeiten',
'Edit customer' => 'Kunde bearbeiten',
'Add new customer by clicking add' => 'Durch Klick auf "Anlegen" neuen Kunden erstellen',
'Existing customers' => 'Bestehende Kunden',
@@ -31,5 +33,6 @@ return [
'Are you sure you want to delete the address?' => 'Sicher, dass die Adresse gelöscht werden soll?',
'Once the address is deleted, all the ressources and data will be permanently deleted.' => 'Sobald die Adresse gelöscht wird, werden alle Ressourcen und Daten dauerhaft gelöscht.',
'Enter your customer\'s address.' => 'Gib die Adresse des Kunden ein.',
+ 'Hint edit address.' => 'Bei bestehenden Adressen kann nur gewählt werden, ob es sich um eine Rechnungs- oder Versandadresse handelt. Die Bearbeitung der anderen Felder ist unterbunden, da diese Daten Einfluss auf bereits bestehende Rechnungen haben.'
];
diff --git a/lang/de/invoice.php b/lang/de/invoice.php
index 43a46dc..c73596f 100644
--- a/lang/de/invoice.php
+++ b/lang/de/invoice.php
@@ -19,6 +19,8 @@ return [
'Existing invoices' => 'Bestehende Rechnungen',
'Create new invoice' => 'Neue Rechnung anlegen',
'Select customer' => 'Kunde auswählen',
+ 'Select address' => 'Adresse auswählen',
+ 'Search customer' => 'Kunden suchen',
'Select your customer and address' => 'Wähle einen Kunden und seine Adresse aus',
'Invoice item' => 'Rechnungsposition',
'Invoice items' => 'Rechnungspositionen',
diff --git a/resources/views/address/edit.blade.php b/resources/views/address/edit.blade.php
new file mode 100644
index 0000000..edca244
--- /dev/null
+++ b/resources/views/address/edit.blade.php
@@ -0,0 +1,129 @@
+
+ {{ __("customer.Hint edit address.") }}
+
+ {{ __('customer.Edit existing address') }}
+
+
+ {{ __('customer.Edit address') }}
+
+