Basic usage of laravel form verification Exists rules

Source: Internet
Author: User
{Code ...} the above is the verification rule {code ...} check whether the markets Table Name of the database mysql_card exists. Unfortunately, the following error is returned when writing this id. {code ...} there is no unique: mysql_card.operators, phoneunique this...
public function rules(){   return [            'phone'       => 'required|digits_between:10,12|unique:mysql_card.operators,phone',            'name'       => 'required',            'market_id'       => 'required|exists:mysql_card.markets,id',            'email' => 'required|email|unique:operators,email',            'password' => 'required|max:20',            'login_name' => 'required|numeric|max:10|unique:mysql_card.operators,login_name',        ]; }    

The above are verification rules

'market_id'       => 'required|exists:mysql_card.markets,id',

Whether the secondary verification existsmysql_cardThis databasemarketsWhether the table name existsid

Unfortunately, this write is wrong.

The following error is reported;

QueryException in Connection. php line 636: SQLSTATE [42S02]: Base table or view not found: 1146 Table 'Hi _ hi_mysql_card.markets 'doesn' t exist (SQL: select count (*) as aggregate from 'Hi _ hi_mysql_card '. 'markets 'where 'id' = 1) The table prefix is 'Hi _'

Andunique:mysql_card.operators,phone uniqueThe verification rule is the same as that for accessing the configured database.

'Mysql _ Card' is the name of the database configured in 'config '.

exists:Does the specified database not support verification? You can also add other solutions to the specified database.

This is the database configuration information. The second database configuration information needs to be verified.mysql_card

'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,],

Reply content:
public function rules(){   return [            'phone'       => 'required|digits_between:10,12|unique:mysql_card.operators,phone',            'name'       => 'required',            'market_id'       => 'required|exists:mysql_card.markets,id',            'email' => 'required|email|unique:operators,email',            'password' => 'required|max:20',            'login_name' => 'required|numeric|max:10|unique:mysql_card.operators,login_name',        ]; }    

The above are verification rules

'market_id'       => 'required|exists:mysql_card.markets,id',

Whether the secondary verification existsmysql_cardThis databasemarketsWhether the table name existsid

Unfortunately, this write is wrong.

The following error is reported;

QueryException in Connection. php line 636: SQLSTATE [42S02]: Base table or view not found: 1146 Table 'Hi _ hi_mysql_card.markets 'doesn' t exist (SQL: select count (*) as aggregate from 'Hi _ hi_mysql_card '. 'markets 'where 'id' = 1) The table prefix is 'Hi _'

Andunique:mysql_card.operators,phone uniqueThe verification rule is the same as that for accessing the configured database.

'Mysql _ Card' is the name of the database configured in 'config '.

exists:Does the specified database not support verification? You can also add other solutions to the specified database.

This is the database configuration information. The second database configuration information needs to be verified.mysql_card

'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,],

There are still some methods. You can extend laravel's verification class and write your own method.

Table 'hi_hi_mysql_card.markets' doesn't existThere are actually hiHiMysql_card database and table markets? The table prefix ishi_?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.