Home > PHP Framework > ThinkPHP > A small test about thinkphp validator

A small test about thinkphp validator

藏色散人
Release: 2021-10-28 16:03:36
forward
1373 people have browsed it

The followingthinkphp frameworktutorial column will introduce you to a small test about the thinkphp validator. I hope it will be helpful to friends in need!

A small test about thinkphp validator

tp validator sorting

Verify whether the data is unique according to the data table fields. No more words, just go to the code

    protected $rule = [
        'com_id|公司机构' => 'require',
        'user_id|用户' => 'require',
        'type|类型' => 'require',
        'name|名称' => 'require|unique:ProSup,name^com_id^type',
    ];
Copy after login

Generated SQL statement:

SELECT `id` FROM `lyx_pro_sup` WHERE ( `name` = 'lyx32609@163.com' AND `com_id` = 1 AND `type` = 4 ) AND `lyx_pro_sup`.`delete_time` = 0 LIMIT 1 ;
Copy after login

Because I used soft deletion, all the delete_time conditions are added

Note: I only tested this on tp5, other frameworks are only for reference

Recommended: "The latest 10 thinkphp video tutorials"

The above is the detailed content of A small test about thinkphp validator. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.im
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template