'required|string|max:255', ]; if ($this->method() === 'PUT') { $rules['name'] = 'required|string|max:255|unique:permission_groups,name,' . $this->id; } else { $rules['name'] = 'required|string|max:255|unique:permission_groups'; } return $rules; } public function prepareForValidation() { $this->merge([ 'slug' => Str::slug($this->input('name')), ]); } }