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'