[英]How to update without changing the value of unique fields?
我更新用戶數據。 更新的形式是填寫當前用戶數據。 如果我不更改 email 驗證,則會顯示此 email 已被占用的錯誤。 我使用Rule::unique
來解決這個問題,但這不起作用?
修復之前的答案
class CustomerRequest extends FormRequest
{
public function rules()
{
return [
'first_name' => 'min:3|max:20|regex:/^[a-zA-z-0-9]+$/u',
'last_name' => 'min:3|max:30|regex:/^[a-zA-z-0-9]+$/u',
['email', Rule::unique('customers')->ignore($this->customer->id)]
];
}
另外在你的controller必須收到
public function update(CustomerRequest $request, Customer $customer)
{
//Code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.