Awesome
βοΈ Kakunin
π° Is this useful to you?
Consider sponsoring me on github! π
πΎ Installation
composer require juhlinus/kakunin
π€ Usage
Kakunin relies on Custom Form Requests.
Add the ValidatesInertiaInput
trait to your newly generated form request like so:
<?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 [
//
];
}
}
In order for the validation to be instant you need to make use of a watcher.
Here's an example in 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>
Note that I'm passing a validate
parameter. If this isn't passed then Kakunin will not validate your request.
That's it! Happy validating!
π Configuration
If you wish to change the validate
to something else, then you can add KAKUNIN_VALIDATION_KEY
to your .env
file. Lastly, add the following to your config/services.php
file:
'kakunin' => [
'validation_key' => env('KAKUNIN_VALIDATION_KEY'),
],
β© That's a stupid name for a package
Kakunin(η’Ίθͺ) is the Japanese verb "to validate".