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
This commit is contained in:
Ivan Nieto 2021-02-16 14:52:55 -06:00 committed by GitHub
parent 681c41bd18
commit f89d789832
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -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'));
}

View file

@ -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'