Skip to main content

What is Precognition

Precognition is a mechanism that runs server-side validation before a form is submitted. You can use your Laravel rules as-is on the frontend without redefining them. Unlike normal requests, Precognition requests execute a route’s middleware and form request validation, but not the controller method body itself. That makes it well-suited to real-time validation as the user types.

Installation

In Laravel 13, you don’t need to install the backend laravel/precognition package. What you do need is a frontend helper package.
  • Vue: laravel-precognition-vue
  • React: laravel-precognition-react
  • Alpine.js: laravel-precognition-alpine
Inertia has built-in Precognition support from 2.3, and it also works out of the box in Inertia 3. When using Inertia forms, you typically don’t need to add laravel-precognition-vue / laravel-precognition-react.

Backend configuration

Add the HandlePrecognitiveRequests middleware to your route. It’s practical to gather validation rules into a form request. Consolidating rules into a form request makes reuse and separation of concerns easier.
If you have custom middleware with side effects, skip them during Precognition.

Frontend integration

Alpine.js (Blade)

Vue (Inertia.js)

React (Inertia.js)

Vanilla JS with Axios

The Precognition library uses Axios. To use your existing Axios instance, swap it in with client.use().

Controlling validation timing

Use validate() to validate individual inputs.
You can adjust the debounce time with setValidationTimeout().
If you want to validate files every time, use validateFiles().
You can validate array inputs using wildcards.

Form helper

useForm() handles submission and error state together.
  • validating: A validation request is in progress
  • processing: A submission is in progress
  • errors: A list of errors
  • valid('field') / invalid('field'): The field’s validation state
  • submit(): Perform a regular submission

Comparing regular requests and Precognition requests

The diagram below shows the difference between how regular and Precognition requests are handled.
Last modified on July 13, 2026