gpt4 book ai didi

laravel - 编辑中的字段唯一(已采用)?

转载 作者:行者123 更新时间:2023-12-02 04:01:19 25 4
gpt4 key购买 nike

我在编辑用户时遇到验证问题。因此,当我编辑时,我收到消息称该名称已被占用。我怎样才能解决这个问题?因为该名称属于该用户。所以我需要再次更改名称,以便我可以编辑我的用户。

    if($user->business_user){
$this->validate($request,[
'company_name' => 'required|unique:business_users'
]);
}

我的看法:

<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group" v-bind:class="{ 'has-error': basic_errors.company_name }">
<label class="form_title">COMPANY NAME</label>
<input type="text" name="company_name" v-model="basic_credentials.company_name" value="{{ is_value_empty($user->business_user->company_name) }}" class="form_input">
<span class="help-block" id="helpBlock2" v-show="basic_errors.company_name">@{{ basic_errors.company_name }}</span>
</div>
</div>

最佳答案

Sometimes, you may wish to ignore a given ID during the unique check. For example, consider an "update profile" screen that includes the user's name, e-mail address, and location. Of course, you will want to verify that the e-mail address is unique. However, if the user only changes the name field and not the e-mail field, you do not want a validation error to be thrown because the user is already the owner of the e-mail address.

To instruct the validator to ignore the user's ID, we'll use the Rule class to fluently define the rule. In this example, we'll also specify the validation rules as an array instead of using the | character to delimit the rules:

Validator::make($data, [
'email' => [
'required',
Rule::unique('users')->ignore($user->id),
],
]);

https://laravel.com/docs/5.3/validation#rule-unique

关于laravel - 编辑中的字段唯一(已采用)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41829840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com