rareloop / lumberjack-validation
此包的最新版本(v1.1.1)没有可用的许可证信息。
v1.1.1
2023-04-05 14:11 UTC
Requires
- rakit/validation: ^0.13.1
- rareloop/lumberjack-core: ^5.0.0||^6.0.0
Requires (Dev)
- brain/monkey: ^2.0.2
- codedungeon/phpunit-result-printer: ^0.4.4
- mockery/mockery: ^1.0.0
- phpunit/phpunit: ^6.0
- satooshi/php-coveralls: ^1.0
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-09-05 17:24:10 UTC
README
此包提供了一个简单的方式来验证表单输入。在它的核心中,它是对Rakit Validation库的轻量级包装。有关您可以使用哪些规则的文档,请参阅他们的(Github文档)[https://github.com/rakit/validation。
安装后,在config/app.php
中注册服务提供者
'providers' => [ ... Rareloop\Lumberjack\Validation\ValidationServiceProvider::class, ... ],
现在您可以使用表单对象来验证您的表单提交
创建表单对象
class ContactForm extends AbstractForm { protected $rules = [ 'name' => 'required', 'email' => 'required|email' ]; }
使用表单来验证输入
您可以将表单注入到您的Lumberjack控制器中,然后使用这个
use App\Forms\ContactForm; class IndexController { public function handle(ContactForm $form) { if ($form->validate($_POST)) { // Everything's good - do something with the input } else { $errors = $form->errors(); $values = $form->values(); // Re-show the form with the errors and entered values } } }