From 71e6a74120eea350cf56d5db171e4c58418d6630 Mon Sep 17 00:00:00 2001
From: chris
Date: Thu, 13 Feb 2025 13:00:44 +0100
Subject: [PATCH] Make customers deletable and recoverable.
---
.../Controllers/Api/CustomerController.php | 18 +++
app/Models/Invoice.php | 2 +-
lang/de/form.php | 1 +
.../views/components/restore-icon.blade.php | 3 +
resources/views/customer/index.blade.php | 118 ++++++++++++++----
routes/api.php | 2 +
6 files changed, 122 insertions(+), 22 deletions(-)
create mode 100644 resources/views/components/restore-icon.blade.php
diff --git a/app/Http/Controllers/Api/CustomerController.php b/app/Http/Controllers/Api/CustomerController.php
index f4ce89c..3544bdf 100644
--- a/app/Http/Controllers/Api/CustomerController.php
+++ b/app/Http/Controllers/Api/CustomerController.php
@@ -18,6 +18,14 @@ class CustomerController extends Controller
return response()->json(Customer::with(['address', 'delivery'])->orderBy('name')->get());
}
+ /**
+ * Display a listing of the resource.
+ */
+ public function withTrashed(): JsonResponse
+ {
+ return response()->json(Customer::with(['address', 'delivery'])->withTrashed()->orderBy('name')->get());
+ }
+
/**
* Store a newly created resource in storage.
*/
@@ -66,4 +74,14 @@ class CustomerController extends Controller
return response()->json(null, 204);
}
+
+ /**
+ * Restore the specified resource.
+ */
+ public function restore(int $id): JsonResponse
+ {
+ $customer = Customer::withTrashed()->findOrFail($id)->restore();
+
+ return response()->json($customer);
+ }
}
diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php
index 4e94a75..e95a1bc 100644
--- a/app/Models/Invoice.php
+++ b/app/Models/Invoice.php
@@ -99,7 +99,7 @@ class Invoice extends Model
*/
public function customer(): BelongsTo
{
- return $this->belongsTo(Customer::class);
+ return $this->belongsTo(Customer::class)->withTrashed();
}
/**
diff --git a/lang/de/form.php b/lang/de/form.php
index edeb6f0..0183172 100644
--- a/lang/de/form.php
+++ b/lang/de/form.php
@@ -14,6 +14,7 @@ return [
'Add' => 'Anlegen',
'Edit' => 'Bearbeiten',
'Delete' => 'Löschen',
+ 'Restore' => 'Wiederherstellen',
'Save' => 'Speichern',
'Change' => 'Ändern',
'SaveAndContinue' => 'Speichern und Weiter',
diff --git a/resources/views/components/restore-icon.blade.php b/resources/views/components/restore-icon.blade.php
new file mode 100644
index 0000000..f474c60
--- /dev/null
+++ b/resources/views/components/restore-icon.blade.php
@@ -0,0 +1,3 @@
+
diff --git a/resources/views/customer/index.blade.php b/resources/views/customer/index.blade.php
index 09215c4..4a92d1a 100644
--- a/resources/views/customer/index.blade.php
+++ b/resources/views/customer/index.blade.php
@@ -19,14 +19,15 @@
{{ __("customer.Add new customer by clicking add") }}
- {{ __('form.Add') }}
+
+ {{ __('form.Add') }}
+
-
+
-
-
{{ __('common.Name') }}
-
{{ __('common.Email') }}
-
{{ __('common.Created at') }}
+
+
+
{{ __('common.Name') }}
+
{{ __('common.Email') }}
+
{{ __('common.Created at') }}
+
+
-
-
-
+
+
+
+
+
+
+ {{ __('form.Delete') }}
+
+
+
+
+
+ {{ __('form.Restore') }}
+
+
@@ -60,16 +88,64 @@
diff --git a/routes/api.php b/routes/api.php
index e00d49a..0a053c3 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -31,6 +31,8 @@ Route::group(['as' => 'api.'], function () {
});
Route::apiResource('/customer', CustomerController::class);
+ Route::get('/customer-with-trashed', [CustomerController::class, 'withTrashed']);
+ Route::get('/customer/{id}/restore', [CustomerController::class, 'restore'])->name('customer.restore');
Route::apiResource('/customer.address', AddressController::class)->shallow();
Route::apiResource('/taxrate', TaxRateController::class)->except(['show']);
Route::get('/invoice-filter/{start}/{end}', [InvoiceController::class, 'index'])->name('invoice.index');