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