创建模型验证器,验证数据正确性
This commit is contained in:
32
app/common/validate/User.php
Normal file
32
app/common/validate/User.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class User extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'username' => 'require|max:255',
|
||||
'password' => 'require|min:6|max:255',
|
||||
'phone' => 'max:32',
|
||||
'email' => 'email',
|
||||
'channel_id' => 'require|integer|gt:0',
|
||||
'status' => 'in:0,1',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['username', 'password', 'phone', 'email', 'channel_id', 'status'],
|
||||
'edit' => ['username', 'password', 'phone', 'email', 'channel_id', 'status'],
|
||||
];
|
||||
|
||||
public function sceneEdit(): static
|
||||
{
|
||||
return $this->only(['username', 'password', 'phone', 'email', 'channel_id', 'status'])
|
||||
->remove('password', 'require');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user