基于 / 动量预航
为Inertia驱动的Laravel应用程序提供实时后端驱动的验证
v0.2.0
2023-04-11 01:40 UTC
Requires
- php: ^8.0
- illuminate/support: ^8.24|^9.0|^10.0
- inertiajs/inertia-laravel: ^0.6.3
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/larastan: ^1.0|^2.0
- orchestra/testbench: ^6.9|^7.0|^8.0
- pestphp/pest: ^1.22|^2.0
- pestphp/pest-plugin-laravel: ^1.3|^2.0
- spatie/laravel-data: ^2.0
This package is auto-updated.
Last update: 2024-09-11 04:44:53 UTC
README
Momentum Preflight是一个Laravel包,允许您为Inertia应用程序实现实时后端驱动的请求验证。
使用Inertia表单助手验证表单请求,就像您已经做的那样,无需运行控制器代码。
安装
Laravel
将包安装到您的Laravel应用程序中。
composer require based/momentum-preflight
注册PreflightMiddleware
中间件。
<?php Route::post('register', RegisterController::class) ->middleware(PreflightMiddleware::class);
Vue 3
由于Laravel社区广泛采用Vue 3,当前前端包仅适用于Vue 3。
安装前端包。
npm i momentum-preflight
# or
yarn add momentum-preflight
使用方法
Preflight可以很好地与表单请求和Laravel Data一起工作。由于该方法简单,它不支持内联$request->validate(...)
方法。
<?php class RegisterController { public function __invoke(RegisterRequest $request) { ... } }
import { useForm } from "inertia/inertia-vue3"; import { useValidate } from "momentum-preflight"; const form = useForm({ name: "" }); const validate = useValidate(form, "/register", { debounce: 500 }); watch( () => form.data(), () => validate() );
该包对所有定义的规则执行验证。然而,您可以指定确切字段,这样在您开始输入时,所有错误不会同时出现。
<script setup> import { useForm } from "inertia/inertia-vue3"; import { useValidate } from "momentum-preflight"; const form = useForm({ name: "" }); const validate = useValidate(form, "/register"); </script> <template> <div> <input v-model="form.name" @blur="validate('name')" /> <span v-if="form.errors.name">{{ form.errors.name }}</span> </div> </template>
高级Inertia
通过我的书高级Inertia将您的Inertia.js技能提升到下一个水平。学习高级概念,并使用Laravel和Inertia.js轻松构建和维护应用程序。
Momentum
Momentum是一组旨在提高您构建Inertia驱动的应用程序体验的包。
- 模态框 — 为Inertia应用程序构建动态模态对话框
- 预航 — Inertia应用程序的实时后端驱动验证
- 分页器 — Laravel分页的无头包装器
- 追踪 — 使用Inertia的前端包来使用Laravel路由
- 锁 — 使用Inertia的前端包来使用Laravel权限
- 布局 — Vue 3应用程序的持久布局
- Vite插件监控 — 在文件更改时运行shell命令的Vite插件
致谢
许可协议
MIT许可(MIT)。有关更多信息,请参阅许可文件。