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!

1 Comments

CAN FEEDBACK
  1. Anonymous
    Anonymous
    Thank you for your lessons, I would like you to give me the procedure to create the mackdown pages (.md) to display the programming lessons in a laravel 12 project with started kit vue
close