美文网首页
Laravel屏蔽敏感词

Laravel屏蔽敏感词

作者: bbdlg | 来源:发表于2019-06-13 11:33 被阅读0次

    使用DFA算法,Laravel有已实现的库:https://github.com/yankewei/laravel-sensitive

    问题1:词库的加载需要在系统启动时添加一次,而非每次需要过滤时都加载一遍

    在SensitiveServiceProvider中的boot方法中加载即可。

    在Laravel的Provider中,所有的register函数调用一遍后,再调用boot函数。

    问题2:SensitiveServiceProvider中的boot方法中调用Sensitive门面方法会提示

    Sensitive::addwords($filename);
    
    ErrorException  : Non-static method Yankewei\LaravelSensitive\Sensitive::addWords() should not be called statically
    

    改为如下方式即可:

    app(Sensitive::class)->addwords($filename); 
    

    相关文章

      网友评论

          本文标题:Laravel屏蔽敏感词

          本文链接:https://www.haomeiwen.com/subject/ajmjfctx.html