juhlinus / kakunin
Fund package maintenance!
juhlinus
Installs: 2 666
Dependents: 0
Suggesters: 0
Security: 0
Stars: 40
Watchers: 5
Forks: 1
Open Issues: 1
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-11-29 05:51:34 UTC
README
π° 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".