唯一电子邮件验证在laravel 5.6中不起作用

时间:2018-08-10 09:50:16

标签: laravel

'email' => 'required|email|unique:connection.tmp_customers,email',

错误是哎呀,好像出了点问题。

2 个答案:

答案 0 :(得分:0)

如果数据库连接为默认连接,则可以省略connection

'email' => 'required|email|unique:tmp_customers,email',

如果您使用的不是默认连接,则需要设置正确的名称:

'custom_name' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

'email' => 'required|email|unique:custom_name.tmp_customers,email',

答案 1 :(得分:0)

尝试这种方式

'email'=> 'required|email|unique:p66_vender,email',

另一种方式

$data->email = $request->get('email')->unique('email');