From f89d789832bcdb175f2c2765204a4ad318acbb73 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Date: Tue, 16 Feb 2021 14:52:55 -0600 Subject: [PATCH] Fixes #8918 The validation rules on Manufacturer Model 'name' attribute are malformed. (#9133) * Fixes the validation rules on Manufacturer Model * Fixes a little issue; if the manufacturer is active soft-deletes it, if is already deleted permanently deletes it --- app/Http/Controllers/ManufacturersController.php | 10 +++++++--- app/Models/Manufacturer.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 7cf14371dc..1943300e30 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -158,7 +158,7 @@ class ManufacturersController extends Controller public function destroy($manufacturerId) { $this->authorize('delete', Manufacturer::class); - if (is_null($manufacturer = Manufacturer::withCount('models as models_count')->find($manufacturerId))) { + if (is_null($manufacturer = Manufacturer::withTrashed()->withCount('models as models_count')->find($manufacturerId))) { return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.not_found')); } @@ -174,8 +174,12 @@ class ManufacturersController extends Controller } } - // Delete the manufacturer - $manufacturer->delete(); + // Soft delete the manufacturer if active, permanent delete if is already deleted + if($manufacturer->deleted_at === NULL) { + $manufacturer->delete(); + } else { + $manufacturer->forceDelete(); + } // Redirect to the manufacturers management page return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.delete.success')); } diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php index 00ac8e7608..085bed2d3f 100755 --- a/app/Models/Manufacturer.php +++ b/app/Models/Manufacturer.php @@ -17,7 +17,7 @@ class Manufacturer extends SnipeModel // Declare the rules for the form validation protected $rules = array( - 'name' => 'required|min:2|max:255|unique:manufacturers,name,NULL,deleted_at', + 'name' => 'required|min:2|max:255|unique:manufacturers,name,NULL,id,deleted_at,NULL', 'url' => 'url|nullable', 'support_url' => 'url|nullable', 'support_email' => 'email|nullable'