AgentSkillsCN

folio-routing

使用 Laravel Folio 创建基于文件的路由。当您新建页面、设置路由规则、处理路由参数或模型绑定、为页面添加中间件、操作 resources/views/pages,或者当用户提及 Folio、页面、基于文件的路由、页面路由,或为某个 URL 路径创建新页面时,此功能将自动激活。

SKILL.md
--- frontmatter
name: folio-routing
description: >-
  Creates file-based routes with Laravel Folio. Activates when creating new pages, setting up
  routes, working with route parameters or model binding, adding middleware to pages, working with
  resources/views/pages; or when the user mentions Folio, pages, file-based routing, page routes,
  or creating a new page for a URL path.

Folio Routing

When to Apply

Activate this skill when:

  • Creating pages with file-based routing
  • Working with route parameters and model binding
  • Adding middleware to Folio pages

Documentation

Use search-docs for detailed Folio patterns and documentation.

Basic Usage

Laravel Folio is a file-based router that creates a new route for every Blade file within the configured directory.

Pages are usually in resources/views/pages/ and the file structure determines routes:

  • pages/index.blade.php/
  • pages/profile/index.blade.php/profile
  • pages/auth/login.blade.php/auth/login

Listing Routes

You may list available Folio routes using php artisan folio:list or using the list-routes tool.

Creating Pages

Always create new folio pages and routes using php artisan folio:page [name] following existing naming conventions.

<code-snippet name="Example folio:page Commands for Automatic Routing" lang="shell">

// Creates: resources/views/pages/products.blade.php → /products {{ $assist->artisanCommand('folio:page "products"') }}

// Creates: resources/views/pages/products/[id].blade.php → /products/{id} {{ $assist->artisanCommand('folio:page "products/[id]"') }}

</code-snippet>

Named Routes

Add a name at the top of each new Folio page to create a named route that other parts of the codebase can reference.

<code-snippet name="Named Routes Example" lang="php">

use function Laravel\Folio\name;

name('products.index');

</code-snippet>

Middleware

<code-snippet name="Middleware Example" lang="php">

use function Laravel\Folio{name, middleware};

name('admin.products'); middleware(['auth', 'verified']);

</code-snippet>

Verification

  1. Run php artisan folio:list to verify route registration
  2. Test page loads at expected URL

Common Pitfalls

  • Forgetting to add named routes to new Folio pages
  • Not following existing naming conventions when creating pages
  • Creating routes manually in routes/web.php instead of using Folio's file-based routing