wayfinder
Original:🇺🇸 English
Translated
How to work effectively with Laravel Wayfinder, always use when developing frontend features
2installs
Added on
NPX Install
npx skill4agent add markhamsquareventures/essentials wayfinderTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →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 after route changes if there are any errors
php artisan wayfinder:generate
Feature Overview
- Form Support: Use with
.form()flag for HTML form attributes —--with-form→<form {...store.form()}>action="/posts" method="post" - HTTP Methods: Call ,
.get(),.post(),.patch(),.put()for specific methods —.delete()→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 for non-controller routes. For example,
@/routes/for route nameimport { show } from '@/routes/post'; show(1)post.show - Parameter Binding: Detects route keys (e.g., ) and accepts matching object properties —
{post:slug}orshow("my-post")show({ slug: "my-post" }) - Query Merging: Use to merge with
mergeQuery, set values towindow.location.searchto remove —nullshow(1, { mergeQuery: { page: 2, sort: null } }) - Query Parameters: Pass in options to append params —
{ query: {...} }→show(1, { query: { page: 1 } })"/posts/1?page=1" - Route Objects: Functions return shaped objects —
{ url, method }→show(1){ url: "/posts/1", method: "get" } - URL Extraction: Use to get URL string —
.url()→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" }Wayfinder + Inertia
If your application uses the 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><Form>