Explanation of Laravel 12 Blog Module Folder Structure
Modular architecture in Laravel 12 enables developers to organize large applications by feature, resulting in a clean, scalable, and easier-to-maintain codebase. In this tutorial, we’ll walk through the
Folder structure of a custom Blog
module.
/Modules └── /Blog ├── /Http │ └── /Controllers │ └── BlogController.php ├── /Models │ └── Post.php ├── /Providers │ └── BlogServiceProvider.php ├── /routes │ └── web.php ├── /Views │ └── index.blade.php ├── /Database │ ├── /migrations │ │ └── create_posts_table.php │ └── /seeders │ └── BlogDatabaseSeeder.php └── module.json
š Modules/Blog/Http/Controllers/
Contains controller files for the Blog module.
-
BlogController.php
handles incoming blog-related requests, such as showing blog posts or storing new ones.
š Modules/Blog/Models/
Contains Eloquent models for the module.
-
Post.php
is the model that interacts with theposts
table in the database.
š Modules/Blog/Providers/
Contains service providers that register routes, views, and other resources.
-
BlogServiceProvider.php
is responsible for bootstrapping the blog module by loading routes, views, translations, etc.
š Modules/Blog/routes/
Contains route definitions.
-
web.php
defines the blog’s web routes (like/blog
,/blog/{slug}
), just like Laravel’sroutes/web.php
file.
š Modules/Blog/Views/
Holds the Blade view files for this module.
-
index.blade.php
is a sample view for displaying a list of blog posts.
š Modules/Blog/Database/migrations/
Contains migration files that define the structure of the blog's database tables.
-
create_posts_table.php
defines the schema for theposts
table.
š Modules/Blog/Database/seeders/
Contains seeders that populate the database with dummy or initial data.
-
BlogDatabaseSeeder.php
Seed theposts
table with sample blog posts.
š Modules/Blog/module.json
A JSON file that defines metadata about the module (name, namespace, service provider). Useful if you plan to load modules dynamically.
{
"name": "Blog",
"namespace": "Modules\\Blog\\",
"provider": "Modules\\Blog\\Providers\\BlogServiceProvider"
}
Conclusion
Using a modular structure in Laravel 12 (like this Blog
module) allows you to:
-
Isolate and manage each feature independently
-
Keep routes, models, views, and controllers organized
-
Scale your app easily as it grows
You can reuse this structure for other features like User
, Shop
, Product
, or Gallery
Keeping your codebase clean and maintainable.