SKILL.blade.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ---
  2. name: wayfinder-development
  3. description: "Use this skill for Laravel Wayfinder which auto-generates typed functions for Laravel controllers and routes. ALWAYS use this skill when frontend code needs to call backend routes or controller actions. Trigger when: connecting any React/Vue/Svelte/Inertia frontend to Laravel controllers, routes, building end-to-end features with both frontend and backend, wiring up forms or links to backend endpoints, fixing route-related TypeScript errors, importing from @/actions or @/routes, or running wayfinder:generate. Use Wayfinder route functions instead of hardcoded URLs. Covers: wayfinder() vite plugin, .url()/.get()/.post()/.form(), query params, route model binding, tree-shaking. Do not use for backend-only task"
  4. license: MIT
  5. metadata:
  6. author: laravel
  7. ---
  8. @php
  9. /** @var \Laravel\Boost\Install\GuidelineAssist $assist */
  10. @endphp
  11. # Wayfinder Development
  12. ## Documentation
  13. Use `search-docs` for detailed Wayfinder patterns and documentation.
  14. ## Quick Reference
  15. ### Generate Routes
  16. Run after route changes if Vite plugin isn't installed:
  17. ```bash
  18. {{ $assist->artisanCommand('wayfinder:generate --no-interaction') }}
  19. ```
  20. For form helpers, use `--with-form` flag:
  21. ```bash
  22. {{ $assist->artisanCommand('wayfinder:generate --with-form --no-interaction') }}
  23. ```
  24. ### Import Patterns
  25. @boostsnippet("Controller Action Imports", "typescript")
  26. // Named imports for tree-shaking (preferred)...
  27. import { show, store, update } from '@/actions/App/Http/Controllers/PostController'
  28. // Named route imports...
  29. import { show as postShow } from '@/routes/post'
  30. @endboostsnippet
  31. ### Common Methods
  32. @boostsnippet("Wayfinder Methods", "typescript")
  33. // Get route object...
  34. show(1) // { url: "/posts/1", method: "get" }
  35. // Get URL string...
  36. show.url(1) // "/posts/1"
  37. // Specific HTTP methods...
  38. show.get(1)
  39. store.post()
  40. update.patch(1)
  41. destroy.delete(1)
  42. // Form attributes for HTML forms...
  43. store.form() // { action: "/posts", method: "post" }
  44. // Query parameters...
  45. show(1, { query: { page: 1 } }) // "/posts/1?page=1"
  46. @endboostsnippet
  47. @if($assist->roster->uses(\Laravel\Roster\Enums\Packages::INERTIA_LARAVEL) || $assist->roster->uses(\Laravel\Roster\Enums\Packages::INERTIA_REACT) || $assist->roster->uses(\Laravel\Roster\Enums\Packages::INERTIA_VUE) || $assist->roster->uses(\Laravel\Roster\Enums\Packages::INERTIA_SVELTE))
  48. ## Wayfinder + Inertia
  49. @if($assist->inertia()->hasFormComponent())
  50. Use Wayfinder with the `<Form>` component:
  51. @if($assist->roster->uses(\Laravel\Roster\Enums\Packages::INERTIA_REACT))
  52. @boostsnippet("Wayfinder Form (React)", "typescript")
  53. <Form {...store.form()}><input name="title" /></Form>
  54. @endboostsnippet
  55. @endif
  56. @if($assist->roster->uses(\Laravel\Roster\Enums\Packages::INERTIA_VUE))
  57. @boostsnippet("Wayfinder Form (Vue)", "vue")
  58. <Form v-bind="store.form()"><input name="title" /></Form>
  59. @endboostsnippet
  60. @endif
  61. @if($assist->roster->uses(\Laravel\Roster\Enums\Packages::INERTIA_SVELTE))
  62. @boostsnippet("Wayfinder Form (Svelte)", "svelte")
  63. <Form {...store.form()}><input name="title" /></Form>
  64. @endboostsnippet
  65. @endif
  66. @else
  67. Use Wayfinder with `useForm`:
  68. @boostsnippet("Wayfinder useForm", "typescript")
  69. import { store } from "@/actions/App/Http/Controllers/ExampleController";
  70. const form = useForm({ name: "My Big Post" });
  71. form.submit(store());
  72. @endboostsnippet
  73. @endif
  74. @endif
  75. ## Verification
  76. 1. Run `{{ $assist->artisanCommand('wayfinder:generate') }}` to regenerate routes if Vite plugin isn't installed
  77. 2. Check TypeScript imports resolve correctly
  78. 3. Verify route URLs match expected paths
  79. ## Common Pitfalls
  80. - Using default imports instead of named imports (breaks tree-shaking)
  81. - Forgetting to regenerate after route changes
  82. - Not using type-safe parameter objects for route model binding