- How does Laravel Folio differ from traditional route definitions in routes/web.php?
- Folio replaces file-based route definitions with a database-driven approach, where routes are tied to page entries in the `folio_pages` table. This is ideal for dynamic content like CMS or marketing sites, but adds a small lookup overhead (~1–5ms per request). You can still use traditional routes alongside Folio by mounting it explicitly with `Folio::mount()`.
- Can I use Laravel Folio with Laravel 10 or older versions?
- Folio officially supports Laravel 11–13 and PHP 8.1–8.5. If you're on Laravel 10 or older, you’ll need to check compatibility manually or wait for an update, as the package is tightly integrated with newer Laravel features like Symfony 6/7 components.
- How do I migrate existing routes from routes/web.php to Folio?
- Folio doesn’t replace routes entirely—it mounts alongside them. Start by creating Folio pages for new content, then gradually migrate old routes. Use `Folio::mount('/pages/*')` to scope Folio routes and avoid conflicts. For existing routes, keep them in `routes/web.php` until fully transitioned.
- Does Folio support multi-tenant or multi-site setups with custom domains/subdomains?
- Yes, Folio allows routing pages to subdomains or custom domains (e.g., `blog.example.com`). You can configure this via the `domain` field in the `folio_pages` table or use middleware to dynamically resolve domains. This is useful for multi-tenant apps or locale-based routing.
- How do I handle SEO-friendly URLs with Folio’s slug-based routing?
- Folio uses slugs for dynamic routes (e.g., `/content/{slug}`), which can conflict with SEO-friendly URLs like `/blog/post`. Mitigate this by using custom resolvers, prefixes (e.g., `/content/{slug}`), or by configuring your CMS to generate SEO-optimized slugs. Test with tools like Screaming Frog to validate URL structures.
- Can I apply middleware (e.g., auth, A/B testing) to specific Folio pages?
- Yes, Folio integrates with Laravel’s middleware pipeline. You can assign middleware to pages via the `middleware` field in the `folio_pages` table or use terminable middleware for post-processing (e.g., analytics). For A/B testing, use feature flags in middleware or leverage Folio’s `ViewMatched` events.
- What are the performance implications of using Folio in production?
- Folio adds ~1–5ms per request for database lookups, which is negligible for most content-heavy apps. To optimize, cache routes with `php artisan route:cache` or use Redis for the `folio_pages` table. For high-traffic sites, pre-load pages or use Folio’s versioning sparingly to avoid query bloat.
- How do I test Folio routes in PHPUnit without a full database setup?
- Use Folio’s test helpers or database transactions to mock the `folio_pages` table. For example, seed test pages with `Folio::actingAs()` or use `Folio::fake()` to simulate page resolution. Avoid hitting the database in unit tests by focusing on controller logic instead of route resolution.
- Does Folio work with headless CMS platforms like Strapi or Contentful?
- Yes, Folio is designed for headless CMS integrations. You can dynamically fetch page data from Strapi/Contentful and map it to Folio’s `folio_pages` table. Use custom resolvers to handle API responses or sync content via webhooks. Folio’s decoupled template paths (e.g., `resources/views/{slug}.blade.php`) make this flexible.
- What alternatives exist if I need file-based routing but with some Folio features?
- For file-based routing with dynamic content, consider Laravel’s built-in route caching (`php artisan route:cache`) or packages like `spatie/laravel-routing` for modular routes. If you need database-driven routing but want to avoid Folio’s overhead, explore `spatie/laravel-medialibrary` for content-heavy apps or build a custom solution with Eloquent and middleware.