Modular Laravel 12: Blog Module Folder Structure Explained

Modular Laravel 12: Blog Module Folder Structure Explained

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 the posts 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’s routes/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 the posts table.

šŸ“ Modules/Blog/Database/seeders/

Contains seeders that populate the database with dummy or initial data.

  • BlogDatabaseSeeder.php Seed the posts 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.

Souy Soeng

Souy Soeng

Hi there šŸ‘‹, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
šŸ‘Æ I’m looking to collaborate on open-source PHP & JavaScript projects
šŸ’¬ Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
close