- How does Laravel Folio replace traditional route definitions in Laravel?
- Folio replaces manual route definitions in `routes/web.php` by mapping files in your `resources/pages/` directory to routes. For example, `resources/pages/about.blade.php` automatically becomes `/about`. You still use Laravel’s middleware, controllers, and Blade templates, but routing is managed via filesystem conventions or a database table.
- Can I use Folio for a CMS or marketing site where content changes frequently?
- Yes, Folio is ideal for CMS-like applications. You can store pages in a `folio_pages` database table, allowing non-technical users to edit content via a custom admin panel (e.g., Laravel Nova) or directly in the database. Folio supports dynamic slugs, metadata, and even A/B testing via the `priority` field.
- What Laravel versions does Folio support, and how do I install it?
- Folio supports Laravel 11–13 and PHP 8.4–8.5. Installation is simple: run `composer require laravel/folio`, then execute `php artisan folio:install`. This generates the `folio_pages` migration, model, and config files. No additional setup is needed for basic usage.
- How do I handle middleware (e.g., auth) with Folio routes?
- Folio integrates seamlessly with Laravel’s middleware. You can assign middleware to individual pages via the `middleware` column in the `folio_pages` table or globally in `config/folio.php`. For terminable middleware (like auth), use the `terminable` option in the config or override the `terminate` method in your `Page` model.
- Can I mix Folio routes with traditional Laravel routes in the same app?
- Absolutely. Folio coexists with Laravel’s native routing. For example, you can keep API routes in `routes/api.php` while using Folio for page-based routes in `resources/pages/`. The `route()` helper and `routeIs()` methods work identically for both Folio and traditional routes.
- What if I have conflicting routes (e.g., `/posts` vs. `/posts/1`)?
- Folio resolves conflicts using Laravel’s route priority system. If two routes match, the one defined later in `routes/web.php` or with a higher `priority` in the `folio_pages` table takes precedence. Use `php artisan folio:list` to debug and visualize your route hierarchy.
- How do I create a custom admin panel for managing Folio pages?
- Folio provides a `Page` model with relationships for easy integration with admin panels like Laravel Nova or Filament. Extend the model to add custom fields (e.g., `seo_title`, `publish_at`) and create a resource for CRUD operations. Folio’s CLI (`folio:list`, `folio:make`) also helps manage pages programmatically.
- Does Folio support multi-domain or subdomain routing?
- Yes, Folio supports domain-specific routing. Configure the `domains` array in `config/folio.php` to map subdomains (e.g., `blog.example.com`) to specific page directories. You can also use Laravel’s route middleware to enforce domain-specific logic, like `Route::domain('blog.example.com')->group(...).
- How do I optimize Folio for production performance?
- Cache routes with `php artisan route:cache` and enable Folio’s static rendering for performance-critical pages. Add an index to the `slug` column in `folio_pages` to speed up dynamic lookups. For high-traffic sites, consider using Folio’s filesystem-based routing to avoid database queries entirely.
- Are there alternatives to Folio for file-based routing in Laravel?
- Folio is the official Laravel solution, but alternatives include third-party packages like `spatie/laravel-page-routes` or `orchid/platform` (for admin panels). However, Folio stands out for its deep Laravel integration, minimal boilerplate, and support for both database-driven and filesystem-based routing out of the box.