该电子邮件已经被接收

时间:2019-09-19 11:10:15

标签: email-validation validationerror laravel-6

我正在使用Laravel 6.0,并且试图创建一个仪表板,用户可以在其中更新其信息,但是我面临的一个问题是绕过unique:validator中的用户。

如果用户希望保留相同的电子邮件,验证程序将显示错误消息“电子邮件已被接收”,并且用户不应将电子邮件更改为另一个由用户保留的电子邮件。

如果该用户是唯一拥有此电子邮件的用户,如何避免这种验证。

UserUpdateRequest.php文件:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserUpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'email' => 'email|required|unique:users,email,' . $this->route("users"),
            'password' => 'required_with:password_confirmation|confirmed'
        ];
    }
}

UserStoreRequest.php文件:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'email' => 'email|required|unique:users',
            'password' => 'required|confirmed'
        ];
    }
}

0 个答案:

没有答案