Validation rules for laravel form form validation
怪我咯
怪我咯 2017-05-16 16:55:44
0
2
572

In laravel, when verifying whether fields are repeated, it is as follows

'email' => 'required|email|unique:users'

Verified unique:users

Queryusers Whether there are duplicates in the table;

But this is a single database operation;

The current system needs to verify is not the database I want

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => 'hi_',
            'strict'    => false,
        ],
        'mysql_card' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => 'hi_user',
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => 'hi_',
            'strict'    => false,
        ],


Two databases are set up in the database configuration file;

I want to verify now mysql_card this database

Can anyone give me some guidance?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
阿神
'email' => 'required|email|unique:mysql_card.users'
洪涛

The once and for all solution is to customize the validation rules:

//创建一条"foo"规则
Validator::extend('foo', function($field,$value,$parameters){
 return $value == 'foo';
});

// 使用foo规则
'email' => 'required|foo'

This will be much more flexible.

My laravel tutorial column: /u/biaoyansu/blogs

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template