Skip to content

Conversation

@big-dream
Copy link
Contributor

@big-dream big-dream commented Dec 20, 2024

控制器代码:

dump(validate(\app\validate\ActiviesValidate::class)->scene('create')->check([
    'id' => '',
    'name' => '',
    'location' => '',
    'status' => '',
    'start_time' => '',
    'end_time' => '',
    'off_sale_time' => '',
]));

验证器代码:

<?php
namespace app\validate;

use think\Validate;

class ActiviesValidate extends Validate
{
    protected $must = [
        'name', 'location', 'start_time', 'end_time', 'off_sale_time'
    ];
    protected $rule = [
        'id' => 'number',
        'name' => 'max:30',
        'location' => 'max:50',
        'status' => 'in:0,1',
        'start_time' => 'number',
        'end_time' => 'number|gt:start_time',
        'off_sale_time' => 'number|lt:start_time',
    ];
    public function sceneCreate()
    {
        return $this;
    }
    public function sceneUpdate()
    {
        $this->must = ['id'];
        return $this;
    }
}

@big-dream big-dream linked an issue Dec 20, 2024 that may be closed by this pull request
@liu21st liu21st merged commit fc1bb6e into top-think:8.x Dec 24, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

验证器must无效

2 participants