Download the PHP package efati/laravel-module-generator without Composer
On this page you can find all versions of the php package efati/laravel-module-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download efati/laravel-module-generator
More information about efati/laravel-module-generator
Files in efati/laravel-module-generator
Package laravel-module-generator
Short Description Laravel Module Generator with Repository/Service/DTO/Provider/Test
License MIT
Homepage https://github.com/efati/laravel-module-generator
Informations about the package laravel-module-generator
Laravel Module Generator
A Laravel package to generate fully structured modules (Model, Repository, Service, Interface, DTO, Controller, Form Requests, and Tests) with a single Artisan command.
Features
- Generate Model, Repository, Service, Interface, DTO, Controller, Form Requests, and Tests in one command
- Supports API Resource controllers
- Dynamic namespace and path configuration via
config/module-generator.php
- Automatic binding of Repository and Service in Service Providers
- Generates CRUD Feature Tests with both success and failure scenarios
- Respects your existing
.env
database configuration for tests (no forced SQLite) - Ability to override stubs
- Compatible with Laravel 10+ and Laravel 11
- Built-in
goli()
helper for Jalali date handling (no external dependency)
Installation
Configuration
Publish the configuration file:
This will create config/module-generator.php
where you can adjust:
- Namespace paths for models, repositories, services, controllers, DTOs, and tests
- Default controller path (e.g.,
App\Http\Controllers\Api\V1
) - Enable/Disable generation of tests, form requests, DTOs, etc.
Customising generator stubs
If your team follows specific coding standards you can publish and edit the generator stubs:
All stub files will be copied to resources/stubs/module-generator
. The generators always look for a published stub first, so
any changes you make there (naming conventions, imports, method bodies, docblocks, etc.) will be reflected in the next
generation run. The package uses simple placeholders such as {{ namespace }}
, {{ class }}
or {{ store_argument }}
inside
the stub files—leave these intact and only change the surrounding structure to keep the dynamic parts working.
Usage
Create a module
Options (long form)
Option | Description |
---|---|
--api |
Generate an API-flavoured controller (default path: Http/Controllers/Api/V1 ) |
--controller=Subdir |
Place controller inside a subdirectory (forces controller generation) |
--requests |
Generate Form Requests for Store/Update |
--tests |
Force CRUD Feature Test generation |
--no-controller |
Skip controller generation |
--no-resource |
Skip API Resource generation |
--no-dto |
Skip DTO generation |
--no-test |
Skip Feature Test generation |
--no-provider |
Skip provider creation and auto-registration |
--from-migration= |
Provide a migration path or keyword to infer fields when the model class does not exist yet |
--force |
Overwrite existing files (default is to skip and warn) |
--fields= |
Inline schema definition so generators can infer fillable fields, validation rules, and test payloads before the Eloquent model exists |
Short aliases
Alias | Long option |
---|---|
-a |
--api |
-c |
--controller |
-r |
--requests |
-t |
--tests |
-nc |
--no-controller |
-nr |
--no-resource |
-nd |
--no-dto |
-nt |
--no-test |
-np |
--no-provider |
-fm |
--from-migration |
-f |
--force |
Example
This will generate:
- Model:
app/Models/Product.php
- Repository:
app/Repositories/Eloquent/ProductRepository.php
- Repository Interface:
app/Repositories/Contracts/ProductRepositoryInterface.php
- Service:
app/Services/ProductService.php
- Service Interface:
app/Services/Contracts/ProductServiceInterface.php
- DTO:
app/DTOs/ProductDTO.php
- Controller:
app/Http/Controllers/Api/V1/Admin/ProductController.php
- Form Requests:
app/Http/Requests/StoreProductRequest.php
&UpdateProductRequest.php
- Feature Tests:
tests/Feature/ProductCrudTest.php
Tip: rerunning the generator without
--force
will skip existing files and list the skipped paths in the console output.New in v4: you can prime the generator with a migration when the Eloquent model class is not ready yet:
The command will scan the migration, infer columns, nullable/unique flags, and foreign keys, then feed that metadata to the DTO, FormRequest, Resource, and Feature Test generators.
Test Generation
When using --tests
, the package will:
- Use the database connection defined in
.env
- Run CRUD operations with valid data and invalid data scenarios
- Test for
404 Not Found
when accessing non-existent records - Test validation errors from Form Requests
- Test successful creation, update, and deletion
Goli Date Helper
The package now ships with an in-house Jalali toolkit exposed via the goli()
helper and the Goli
class, so you can
drop the third-party Verta dependency and reuse the converter anywhere in your project.
Key capabilities include:
- parsing Jalali date strings (with optional Persian/Arabic digits) via
goli()
orGoli::parseJalali()
- converting Jalali dates to Gregorian and vice versa, including array helpers and timezone awareness
- formatting output with automatic Persian digit localisation when desired
- seamless Carbon interoperability for chained date operations
- resolving new instances through the Laravel container using the
goli
binding
Carbon Jalali Macros
When the service provider boots it registers two Carbon macros, giving you an instant bridge between Carbon
and Goli
:
The toJalali()
macro returns a Goli
instance, so you keep access to all Jalali helpers (digit localisation, formatting helpers, etc.).
fromJalali()
gives you a regular Carbon
instance back for further chaining. Both macros accept an optional timezone argument and are only registered once, so you can safely call the service provider multiple times (or invoke ModuleGeneratorServiceProvider::registerCarbonMacros()
manually in a console script).
Looking for a quick smoke test? Run
php tests/CarbonMacrosExample.php
to execute the same round-trip conversion showcased above.
Version History
v5.3
- Added short CLI aliases (
-a
,-c
,-r
,-t
, etc.) for faster module generation. - Introduced safe overwrite behaviour: generators skip existing files unless
--force/-f
is provided. - Controllers now adapt to API vs. web mode, respecting DTO/resource toggles and returning sensible payloads when those artefacts are disabled.
- Services fall back to array payloads when DTOs are skipped and can work without provider bindings when
--no-provider
is used.
v5.2
- Added full CRUD Feature Tests with success & failure cases
- Removed forced SQLite in tests (uses
.env
database settings) - Fixed Form Requests generation bug
- Improved DTO integration in Controllers & Services
v5.1
- Bug fixes for Form Requests generation
- Improved path handling in configuration
v5.0
- Major refactor for Laravel 11 support
- Dynamic namespace handling
- Service & Repository auto-binding
License
MIT
پینوشت: با تشکر از gole davoodi 😆