Registry / web-framework / laravel-precognition-vue-inertia

laravel-precognition-vue-inertia

JSON →
library0.8.0jsnpmunverified

Laravel Precognition Vue Inertia is an official frontend integration package designed to bring "live" validation capabilities to Vue 3 applications that utilize Inertia.js for server-driven UI. It enables developers to anticipate the outcome of future HTTP requests to a Laravel backend, primarily for providing real-time feedback on form inputs without requiring full page reloads. The current stable version of this package is `v2.0.0`, aligning with the core Laravel Precognition library's latest major release. Releases generally follow the development cadence of the broader Laravel ecosystem, with updates often introduced in sync with new Laravel framework versions or significant improvements to the core Precognition package. Its primary differentiator lies in its deep and seamless integration with Laravel's robust validation system and Inertia.js's simplified approach to building single-page applications, offering a highly streamlined developer experience for creating dynamic, interactive forms with instant server-side validation feedback.

npm install laravel-precognition-vue-inertia
INSTALL
IMPORT
SIG · LARAVEL-PRECOGNITI
L
laravel-precognition-vue-inertia
web-frameworkjavascriptv0.8.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useForm
import { useForm } from 'laravel-precognition-vue-inertia';
import useForm from 'laravel-precognition-vue-inertia';
The primary composition function for creating Precognition-enabled forms. It is a named export.
PrecognitionForm
import type { PrecognitionForm } from 'laravel-precognition-vue-inertia';
import { PrecognitionForm } from 'laravel-precognition-vue-inertia';
Type-only import for the form instance; not available at runtime.
Form
import type { Form } from 'laravel-precognition-vue-inertia';
Type-only import for the form data structure.

This quickstart demonstrates how to use `useForm` to create a basic user creation form with live validation using Laravel Precognition and Vue 3 with Inertia.js.

import { defineComponent } from 'vue'; import { useForm } from 'laravel-precognition-vue-inertia'; interface UserForm { name: string; email: string; password?: string; } export default defineComponent({ setup() { const form = useForm<UserForm>('post', '/users', { name: '', email: '', password: '', }); const submit = () => { form.submit({ onSuccess: () => { console.log('User created successfully, redirecting...'); form.reset(); // Example: Inertia.visit('/users'); }, onError: (errors) => { console.error('Validation errors:', errors); }, }); }; return { form, submit, }; }, template: ` <form @submit.prevent="submit"> <div> <label for="name">Name:</label> <input id="name" type="text" v-model="form.name" @change="form.validate('name')" /> <div v-if="form.hasErrors('name')" style="color: red;">{{ form.errors.name }}</div> </div> <div> <label for="email">Email:</label> <input id="email" type="email" v-model="form.email" @change="form.validate('email')" /> <div v-if="form.hasErrors('email')" style="color: red;">{{ form.errors.email }}</div> </div> <div> <label for="password">Password:</label> <input id="password" type="password" v-model="form.password" @change="form.validate('password')" /> <div v-if="form.hasErrors('password')" style="color: red;">{{ form.errors.password }}</div> </div> <button type="submit" :disabled="form.processing || form.hasErrors()"> Create User </button> </form> ` });
Debug
Known issues
breakingStarting with `v2.0.0`, the package replaced the underlying HTTP client from Axios to the native `fetch` API. If you had custom Axios configurations or adapters, they will no longer be used.
fix
Migrate any custom request logic to use the `fetch` API or the package's new configuration options. Review the changelog for specific configuration changes regarding XSRF tokens and `Accept` headers.
affects: >=2.0.0
breakingIn `v1.0.0`, the core `laravel-precognition` package removed its direct dependency on Inertia.js specific code, making `laravel-precognition-vue-inertia` the dedicated integration. While this package continues to provide Inertia support, ensure you are using the correct `laravel-precognition-vue-inertia` package for Inertia-based applications.
fix
Confirm `laravel-precognition-vue-inertia` is installed and properly imported. If migrating from older versions of the core `laravel-precognition` that had built-in Inertia support, update your imports to this dedicated package.
affects: >=1.0.0
gotchaTypeScript support for wildcard validation paths (e.g., `items.*.name`) was introduced in `v1.0.1` for the core package. If you are using an older version and relying on complex nested validation, TypeScript might not correctly infer types.
fix
Upgrade to `v1.0.1` or newer to ensure correct TypeScript typing for wildcard validation paths. Manual type assertions might be necessary for older versions.
affects: <1.0.1
gotchaFull support for Inertia 2.0 was added from `v0.5.14` of the underlying monorepo. If encountering issues with Inertia 2.0 features, ensure your `laravel-precognition-vue-inertia` version is up to date.
fix
Update `laravel-precognition-vue-inertia` to `v0.5.14` or newer to guarantee compatibility and full support for Inertia 2.0 features.
affects: <0.5.14
Errors
Common errors & fixes
TypeError: useForm is not a function
`useForm` was imported incorrectly (e.g., as a default import or from a wrong path) or the package is not installed.
fix
Ensure `laravel-precognition-vue-inertia` is installed and `useForm` is imported as a named export: `import { useForm } from 'laravel-precognition-vue-inertia';`.
Failed to load resource: the server responded with a status of 422 (Unprocessable Content) or Network Error
This typically indicates that the Laravel backend is not correctly configured for Precognition requests, or the CSRF token is missing/invalid.
fix
Verify your Laravel backend's `Kernel.php` has the `HandlePrecognition` middleware enabled for the web group. Also, ensure the CSRF token is included in your requests (Inertia handles this automatically, but check if custom requests are missing it).
Property 'errors' does not exist on type 'PrecognitionForm<...>' or Property 'hasErrors' does not exist...
This TypeScript error often occurs when `PrecognitionForm` is used with incorrect generic types, or when the form's initial data structure doesn't match the expected type.
fix
Ensure the generic type passed to `useForm` (`useForm<MyFormType>`) accurately reflects the structure of your form data, including all possible fields and their types.
Upgrade
Version history
0.8.0latest on npm
Audit
Dependencies
@inertiajs/vue3requiredRequired for Inertia.js integration with Vue 3.
vuerequiredRequired as the core UI framework.
Agent activity
2 hits · last 30 days
node
2
Resources
laravel-precognition-vue-inertia — npm install laravel-precognition-vue-inertia · libregistry