是一个验证登录的代码,验证代码为
<?php
declare (strict_types = 1);
namespace app\admin\controller;
use think\facade\View;
use think\Request;
use app\admin\validate\Login as L;
use think\exception\ValidateException;
class Login{
    //
    public function index(Request $request){
        if($request->isPost()){
            $data = $request->post();
            $remember = $data['remember'] ?? 0;
            try{
            $result = validate(L::class)->check($data);//halt($result);
            }catch(ValidateException $e){
                halt($e);
            }
            
        }
        return View::fetch();
    }
}
验证器的代码为:
<?php
declare (strict_types = 1);
namespace app\admin\validate;
use think\Validate;
class Login extends Validate
{
    /**
     * 定义验证规则
     * 格式:'字段名' =>  ['规则 1','规则 2'...]
     *
     * @var array
     */
    protected $rule = [
        'username' => 'require|alphaNum|max:20',
        'password' => 'require|alphaNum|length:6,16',
    ];
    /**
     * 定义错误信息
     * 格式:'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'username.require' => '账号不能为空',
        'password.require' => '密码不能为空',
        'username.alphaNum' => '账号只能包含字母和数字',
        'username.max' => '账号字符最大长度为 20',
        'password.alphaNum' => '密码只能包含字母和数字',
        'password.length' => '密码的长度为 6 ~ 16',
    ];
}
执行后报这个错误,请问是哪里出了问题?
#0 [0]Error in Validate.php line 1600
Call to a member function has() on null
     * @param string $msg   错误信息
     * @param mixed  $rule  验证规则数据
     * @param string $title 字段描述名
     * @return string|array
     */
    protected function parseErrorMsg(string $msg, $rule, string $title)
    {
        if (0 === strpos($msg, '{%')) {
            $msg = $this->lang->get(substr($msg, 2, -1));
        } elseif ($this->lang->has($msg)) {
            $msg = $this->lang->get($msg);
        }
        if (is_array($msg)) {
            return $this->errorMsgIsArray($msg, $rule, $title);
        }
        // rule 若是数组则转为字符串
        if (is_array($rule)) {
        ```这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.