search

Home  >  Q&A  >  body text

Validation rules for laravel form form validation

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?

怪我咯怪我咯2796 days ago574

reply all(2)I'll reply

  • 阿神

    阿神2017-05-16 16:57:44

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

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 16:57:44

    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

    reply
    0
  • Cancelreply