如何在Laravel 7中创建权限验证?

izkcnapc  于 2023-02-14  发布在  其他
关注(0)|答案(1)|浏览(118)

我有客户数据的形式,我想检查电话是否存在于数据库中(电话和电话2),甚至检查电话2。如果用户写在两个字段相同的电话不接受。

这里是我验证码:

if($request->customer_id == null) {
            unset($rules['customer_id']);
            $rules['customer_name'] = 'required';
            $rules['customer_address'] = 'required';
            $rules['customer_phone'] = 'max:11|required|unique:customers,phone,phone2';
            $rules['customer_phone2'] = 'max:11|unique:customers,phone,phone2';
            $rules['customer_type'] = 'in:regular,special,jomla';
            $mesages['customer_name.required'] = translate('the name is required');
            $mesages['customer_address.required'] = translate('the address is required');
            $mesages['customer_phone.required'] =translate('the phone is required');
            $mesages['customer_phone.max'] =translate('the phone number is not correct');
            $mesages['customer_phone.unique'] =translate('the phone number is used');
            $mesages['customer_phone2.max'] =translate('the phone number is not correct');
            $mesages['customer_phone2.unique'] =translate('the phone number is used');
yduiuuwa

yduiuuwa1#

你可以试试这个

$rules['customer_phone'] = 'required|max:11|unique:customers,phone|unique:customers,phone2';
    $rules['customer_phone2'] = 'required|max:11|unique:customers,phone|unique:customers,phone2|different:customer_phone';

different规则确保phone和phone2字段包含不同的值。

相关问题