Laravel Wayfinder

VérifiéSûr

Génère des fonctions TypeScript typées pour les routes et contrôleurs Laravel, synchronisant automatiquement le backend et le frontend. Utilisez-le pour importer des méthodes de contrôleur ou des routes nommées, avec prise en charge des paramètres, des méthodes HTTP et du merge de requêtes. Idéal pour bénéficier de la sécurité des types et d'un arbre de secouage optimal dans les applications Laravel + Inertia ou vanilla.

Spar Skills Guide Bot
DeveloppementIntermédiaire
7002/06/2026
Claude CodeCursorWindsurfCopilotCodex
#laravel#wayfinder#typescript#routing#frontend

Recommandé pour

Notre avis

Génère des fonctions et types TypeScript pour les contrôleurs et routes Laravel, assurant la synchronisation entre le backend et le frontend.

Points forts

  • Typage fort entre le backend et le frontend
  • Synchronisation automatique des routes après génération
  • Support des méthodes HTTP, formulaires et paramètres de route
  • Optimisation du tree-shaking grâce aux imports nommés

Limites

  • Nécessite Laravel et l'installation du package Wayfinder
  • Doit être régénéré après chaque modification de route
  • Ne couvre pas tous les cas avancés de routage Laravel
Quand l'utiliser

Lors du développement de fonctionnalités frontend dans une application Laravel nécessitant une gestion de routes typée et sécurisée.

Quand l'éviter

Pour des projets sans Laravel ou lorsque l'application frontend ne nécessite pas de synchronisation avancée avec les routes backend.

Analyse de sécurité

Sûr
Score qualité85/100

The skill contains only development guidance for using a Laravel code-generation package, with no executable commands, no data exfiltration, and no destructive actions. It is purely instructional for frontend development practices.

Aucun point d'attention détecté

Exemples

Generate Wayfinder types after adding a new route
I've added a new route in my Laravel `routes/web.php`. Please run the Wayfinder generation command and show me how to use the new route in a React component with type safety.
Use Wayfinder with Inertia forms
I need to create a form in my Laravel Inertia app using the Wayfinder package. Show me how to generate the form action and method automatically.

name: wayfinder description: How to work effectively with Laravel Wayfinder, always use when developing frontend features

Wayfinder

Instructions

Wayfinder generates TypeScript functions and types for Laravel controllers and routes which you can import into your client side code. It provides type safety and automatic synchronization between backend routes and frontend code.

Development Guidelines

  • Always Prefer named imports for tree-shaking (e.g., import { show } from '@/actions/...')
  • Avoid default controller imports (prevents tree-shaking)
  • Run php artisan wayfinder:generate after route changes if there are any errors

Feature Overview

  • Form Support: Use .form() with --with-form flag for HTML form attributes — <form {...store.form()}>action="/posts" method="post"
  • HTTP Methods: Call .get(), .post(), .patch(), .put(), .delete() for specific methods — show.head(1){ url: "/posts/1", method: "head" }
  • Invokable Controllers: Import and invoke directly as functions. For example, import StorePost from '@/actions/.../StorePostController'; StorePost()
  • Named Routes: Import from @/routes/ for non-controller routes. For example, import { show } from '@/routes/post'; show(1) for route name post.show
  • Parameter Binding: Detects route keys (e.g., {post:slug}) and accepts matching object properties — show("my-post") or show({ slug: "my-post" })
  • Query Merging: Use mergeQuery to merge with window.location.search, set values to null to remove — show(1, { mergeQuery: { page: 2, sort: null } })
  • Query Parameters: Pass { query: {...} } in options to append params — show(1, { query: { page: 1 } })"/posts/1?page=1"
  • Route Objects: Functions return { url, method } shaped objects — show(1){ url: "/posts/1", method: "get" }
  • URL Extraction: Use .url() to get URL string — show.url(1)"/posts/1"

Examples

<code-snippet name="Wayfinder Basic Usage" lang="typescript"> // Import controller methods (tree-shakable) import { show, store, update } from '@/actions/App/Http/Controllers/PostController'
// Get route object with URL and method...
show(1) // { url: "/posts/1", method: "get" }

// Get just the URL...
show.url(1) // "/posts/1"

// Use specific HTTP methods...
show.get(1) // { url: "/posts/1", method: "get" }
show.head(1) // { url: "/posts/1", method: "head" }

// Import named routes...
import { show as postShow } from '@/routes/post' // For route name 'post.show'
postShow(1) // { url: "/posts/1", method: "get" }
</code-snippet>

Wayfinder + Inertia

If your application uses the <Form> component from Inertia, you can use Wayfinder to generate form action and method automatically. <code-snippet name="Wayfinder Form Component (React)" lang="typescript">

<Form {...store.form()}><input name="title" /></Form> </code-snippet>
Skills similaires