If you're working with Laravel and want an easier, more streamlined way to define routes without manually writing them in web.php
, then Laravel Folio is something you should definitely check out!
What Is Laravel Folio?
Laravel Folio is a powerful page based router designed to simplify routing in Laravel applications.
With Laravel Folio, generating a route becomes as effortless as creating a Blade template within your application's resources/views/pages
directory.
Simply put, Laravel Folio lets you define routes based on file structure. For example, if you have a file named about.blade.php
in your views folder, it will automatically create a route /about
βno need to touch the traditional routes file.
Why Use Laravel Folio?
Here are some of its key benefits:
- Quick and Easy: Save time by letting the file structure handle your routes.
- Seamless Blade Integration: Fully compatible with Blade templates, allowing you to build dynamic pages effortlessly.
- Perfect for Small Projects: Ideal for landing pages, prototypes, or simple apps where speed matters.
Hands-On Example
- Install the package:
composer require laravel/folio
- Create a new view file like
home.blade.php
in yourresources/views
folder. - Thatβs it! Laravel will automatically map this file to
/home
.
Summary
Laravel Folio is convenient, especially for projects where simplicity and speed are priorities. To make it easier for others to get started, I created a small repository with practical example and a detailed explanation.
π Check it out here:
https://github.com/YasserElgammal/Laravel-Folio
Give it a try and let me know your thoughts!
Top comments (1)
I don't understand why they used the views, instead of the controllers. This encourages people to come up with solutions to add controller logic to the views.
In the documentation there is an example to bind a user model. It implies the user always exists, because there is no check to verify a user is found.
When you read the following sections you see how the package adds php code to the view. And that is what I mean when I say it encourages bad behaviour.
I always found blade a risky template engine, because it is just a php file where you can add domain-specific language. I know that is how all template engines work. But the best are the ones that make it difficult to add php code. They give you pause to think if what you want to do could be bad in the long run.