Laravel Folio brings file-based routing to Laravel, inspired by Next.js and Nuxt. Create pages by adding Blade files to a directory. At ZIRA Software, Folio accelerates development for content-heavy applications.
Installation
composer require laravel/folio
php artisan folio:install
This creates a resources/views/pages directory for your page files.
Basic Page Routing
resources/views/pages/
├── index.blade.php → /
├── about.blade.php → /about
├── contact.blade.php → /contact
└── blog/
├── index.blade.php → /blog
└── archive.blade.php → /blog/archive
{{-- resources/views/pages/about.blade.php --}}
<x-app-layout>
<h1>About Us</h1>
<p>Welcome to our company.</p>
</x-app-layout>
Dynamic Routes
resources/views/pages/
├── users/
│ └── [id].blade.php → /users/{id}
├── posts/
│ └── [slug].blade.php → /posts/{slug}
└── blog/
└── [...path].blade.php → /blog/* (catch-all)
{{-- resources/views/pages/users/[id].blade.php --}}
<?php
use App\Models\User;
use function Laravel\Folio\render;
render(function ($id) {
return view('pages.users.[id]', [
'user' => User::findOrFail($id),
]);
});
?>
<x-app-layout>
<h1>{{ $user->name }}</h1>
<p>{{ $user->email }}</p>
</x-app-layout>
Route Model Binding
{{-- resources/views/pages/posts/[Post:slug].blade.php --}}
<?php
use App\Models\Post;
?>
<x-app-layout>
<article>
<h1>{{ $post->title }}</h1>
<div>{{ $post->content }}</div>
</article>
</x-app-layout>
{{-- Soft deleted models --}}
{{-- resources/views/pages/posts/[Post:slug].blade.php --}}
<?php
use App\Models\Post;
use function Laravel\Folio\withTrashed;
withTrashed();
?>
Middleware
{{-- resources/views/pages/dashboard/index.blade.php --}}
<?php
use function Laravel\Folio\middleware;
middleware(['auth', 'verified']);
?>
<x-app-layout>
<h1>Dashboard</h1>
<p>Welcome back, {{ auth()->user()->name }}!</p>
</x-app-layout>
// Apply middleware to directory in FolioServiceProvider
use Laravel\Folio\Folio;
Folio::path(resource_path('views/pages/admin'))
->middleware(['auth', 'admin'])
->uri('/admin');
Page Names for URL Generation
{{-- resources/views/pages/users/[id].blade.php --}}
<?php
use function Laravel\Folio\name;
name('users.show');
?>
{{-- In other templates --}}
<a href="{{ route('users.show', ['id' => $user->id]) }}">
View Profile
</a>
Multiple Page Directories
// app/Providers/FolioServiceProvider.php
use Laravel\Folio\Folio;
public function boot(): void
{
Folio::path(resource_path('views/pages'))
->uri('/');
Folio::path(resource_path('views/pages/admin'))
->uri('/admin')
->middleware(['auth', 'admin']);
Folio::path(resource_path('views/pages/api-docs'))
->uri('/docs');
}
Data Loading Patterns
{{-- resources/views/pages/blog/index.blade.php --}}
<?php
use App\Models\Post;
use function Laravel\Folio\render;
render(function () {
$posts = Post::published()
->with('author')
->latest()
->paginate(10);
return view('pages.blog.index', compact('posts'));
});
?>
<x-app-layout>
<h1>Blog</h1>
@foreach($posts as $post)
<article>
<h2>
<a href="/posts/{{ $post->slug }}">
{{ $post->title }}
</a>
</h2>
<p>By {{ $post->author->name }}</p>
</article>
@endforeach
{{ $posts->links() }}
</x-app-layout>
When to Use Folio
Good for:
- Marketing sites
- Documentation
- Content-heavy apps
- Simple CRUD pages
- Rapid prototyping
Better with traditional routing:
- Complex API endpoints
- Heavy business logic
- Resource controllers
- Nested relationships
// Hybrid approach - use both
// routes/web.php for complex routes
Route::resource('orders', OrderController::class);
// Folio for simple pages
// resources/views/pages/about.blade.php
Comparison with Next.js
| Feature | Folio | Next.js |
|---------|-------|---------|
| Dynamic routes | [id].blade.php | [id].tsx |
| Catch-all | [...path].blade.php | [...path].tsx |
| Layouts | Blade components | layout.tsx |
| Middleware | PHP function | middleware.ts |
| Data fetching | render() function | Server Components |
Conclusion
Laravel Folio simplifies routing for content-focused applications. File-based routing reduces boilerplate while maintaining Laravel's powerful features.
Building content sites? Contact ZIRA Software for Laravel Folio development.