juhlinus / kakunin
v2.0.0-beta1
2021-10-01 21:14 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- orchestra/testbench: ^5.1
Suggests
- illuminate/support: Required for redirecting after input has been validated.
- symfony/http-foundation: Required for requests and responses.
This package is auto-updated.
Last update: 2024-09-29 05:29:50 UTC
README
💰 这对你有帮助吗?
考虑 在github上赞助我!🙏
💾 安装
composer require juhlinus/kakunin
🤔 使用方法
Kakunin依赖于自定义表单请求。
将ValidatesInertiaInput
特性添加到您新创建的表单请求中,如下所示
<?php namespace App\Http\Requests; use Kakunin\Concerns\ValidatesInertiaInput; use Illuminate\Foundation\Http\FormRequest; class CustomFormRequest extends FormRequest { use ValidatesInertiaInput; /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return false; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ // ]; } }
为了使验证立即可用,您需要使用一个观察者。
以下是一个Vue.js的示例
<template>
<div>
<input v-model="email">
</div>
</template>
<script>
export default {
watch: {
email: function (email) {
this.$inertia.post('/users', {
email: email,
validate: true,
});
}
}
}
</script>
请注意,我传递了一个validate
参数。如果没有传递此参数,Kakunin将不会验证您的请求。
这就完成了!祝您验证愉快!
📝 配置
如果您想将validate
更改为其他内容,可以将KAKUNIN_VALIDATION_KEY
添加到您的.env
文件中。最后,将以下内容添加到您的config/services.php
文件中
'kakunin' => [ 'validation_key' => env('KAKUNIN_VALIDATION_KEY'), ],
⛩ 这个包的名字很愚蠢
Kakunin(確認)是日语动词“验证”。