Looking to hire Laravel developers? Try LaraJobs

laravel-censor maintained by larva

Description
This is a censor.
Last update
2022/07/28 09:59 (dev-master)
License
Links
Downloads
1 619
Tags

Comments
comments powered by Disqus

laravel-censor

适用于 Laravel 的内容安全审查扩展。

环境需求

  • PHP >= 7.4

安装

composer require larva/laravel-censor -vv

使用

自动审核

use Larva\Censor\Censor;
$censor = Censor::make();
$content= '赚钱啦';
try {
  $content = $censor->textCensor($content);
  if($censor->isMod){
    //需要审核
  }
} catch (CensorNotPassedException $e) {
    //有违禁词
}

表单验证

表单验证只检查是否有违禁词,需要审核的直接是放行的,使用本扩展,再用户发布内容后,建议使用队列异步审核一遍。

$request->validate([
    'name' => ['required', 'string', new TextCensorRule],
]);

$request->validate([
    'name' => ['required', 'string', 'text_censor'],
]);