SKILL.blade.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ---
  2. name: folio-routing
  3. description: "Use this skill for Laravel Folio file-based routing tasks: creating pages with `folio:page`, setting up route parameters or model binding in filenames like `[User].blade.php`, defining named routes with `name()`, applying middleware, debugging Folio 404s, or running `folio:list`. Also trigger when a user is choosing between Folio and web.php for a new page, or wants to add a new URL or page in a Folio-enabled project (`resources/views/pages`). Folio automatically maps Blade templates to routes. Do not trigger for Livewire component, Normal Routing, Standard controller routes, or API endpoints"
  4. license: MIT
  5. metadata:
  6. author: laravel
  7. ---
  8. @php
  9. /** @var \Laravel\Boost\Install\GuidelineAssist $assist */
  10. @endphp
  11. # Folio Routing
  12. ## Documentation
  13. Use `search-docs` for detailed Folio patterns and documentation.
  14. ## Basic Usage
  15. Laravel Folio is a file-based router that creates a new route for every Blade file within the configured directory.
  16. Pages are usually in `resources/views/pages/` and the file structure determines routes:
  17. - `pages/index.blade.php` → `/`
  18. - `pages/profile/index.blade.php` → `/profile`
  19. - `pages/auth/login.blade.php` → `/auth/login`
  20. ### Listing Routes
  21. You may list available Folio routes using `{{ $assist->artisanCommand('folio:list') }}`.
  22. ### Creating Pages
  23. Always create new `folio` pages and routes using `{{ $assist->artisanCommand('folio:page [name]') }}` following existing naming conventions.
  24. @boostsnippet("Example folio:page Commands for Automatic Routing", "shell")
  25. // Creates: resources/views/pages/products.blade.php → /products
  26. {{ $assist->artisanCommand('folio:page "products"') }}
  27. // Creates: resources/views/pages/products/[id].blade.php → /products/{id}
  28. {{ $assist->artisanCommand('folio:page "products/[id]"') }}
  29. // Creates: resources/views/pages/users/[User].blade.php → /users/{user} (implicit model binding)
  30. {{ $assist->artisanCommand('folio:page "users/[User]"') }}
  31. @endboostsnippet
  32. ## Route Parameters vs. Model Binding
  33. Use the correct filename token based on intent:
  34. - `[id]` (lowercase) captures a plain route parameter string
  35. - `[User]` (capitalized model class) enables implicit Eloquent model binding
  36. - `[Post:slug]` binds by a custom key instead of `id`
  37. Model binding is case-sensitive in the filename. Avoid `[user]` when you expect a `User` model instance.
  38. @boostsnippet("Route Parameter vs Model Binding Example", "blade")
  39. {{-- pages/users/[id].blade.php --}}
  40. <div>User ID: {{ $id }}</div>
  41. {{-- pages/users/[User].blade.php --}}
  42. <div>User ID: {{ $user->id }}</div>
  43. @endboostsnippet
  44. ## Named Routes
  45. Add a `name` at the top of each new Folio page to create a named route that other parts of the codebase can reference.
  46. @boostsnippet("Named Routes Example", "php")
  47. use function Laravel\Folio\name;
  48. name('products.index');
  49. @endboostsnippet
  50. ## Middleware
  51. @boostsnippet("Middleware Example", "php")
  52. use function Laravel\Folio\{name, middleware};
  53. name('admin.products');
  54. middleware(['auth', 'verified']);
  55. @endboostsnippet
  56. ## Page Content Patterns
  57. Folio pages are normal Blade files. Include practical data-loading code when creating or editing pages.
  58. @boostsnippet("Inline Query Example in a Folio Page", "blade")
  59. @php
  60. use App\Models\Post;
  61. $posts = Post::query()
  62. ->whereNotNull('published_at')
  63. ->latest('published_at')
  64. ->get();
  65. @endphp
  66. <ul>
  67. @foreach ($posts as $post)
  68. <li>{{ $post->title }}</li>
  69. @endforeach
  70. </ul>
  71. @endboostsnippet
  72. @boostsnippet("Render Hook Example for View Data", "php")
  73. <?php
  74. use App\Models\Post;
  75. use Illuminate\View\View;
  76. use function Laravel\Folio\render;
  77. render(function (View $view, Post $post) {
  78. return $view->with('photos', $post->author->photos);
  79. });
  80. ?>
  81. @endboostsnippet
  82. ## Verification
  83. 1. Run `{{ $assist->artisanCommand('folio:list') }}` to verify route registration
  84. 2. Test page loads at expected URL
  85. ## Common Pitfalls
  86. - Forgetting to add named routes to new Folio pages
  87. - Using `[id]` or `[user]` when model binding requires `[User]`
  88. - Not following existing naming conventions when creating pages
  89. - Creating routes manually in `routes/web.php` instead of using Folio's file-based routing
  90. ### Folio 404 Debug Checklist
  91. 1. Run `{{ $assist->artisanCommand('folio:list') }}`
  92. 2. If routes are missing, confirm Folio is mounted (`folio:install` + provider registration, or `Folio::path(...)`) and pages are under the mounted path
  93. 3. Verify filename-to-route mapping (`index.blade.php`, nested paths, `[id]` vs `[Model]`), then rerun `{{ $assist->artisanCommand('folio:list') }}`