Installation Run:
composer require holdmyglass/zapcraft
The package auto-installs nwidart/laravel-modules if missing.
Publish Config & Assets Publish the package config and stubs:
php artisan vendor:publish --provider="HoldMyGlass\ZapCraft\ZapCraftServiceProvider"
Configure Modules
Edit config/zapcraft.php to define your module structure (e.g., modules/ path, namespace prefixes).
Generate First Entity
Run the zapcraft:make command with a basic entity name:
php artisan zapcraft:make Post
This creates:
app/Modules/Post/Entities/Post.php)database/migrations/xxxx_create_posts_table.php)app/Modules/Post/Http/Controllers/PostController.php)app/Modules/Post/Repositories/PostRepositoryInterface.php, PostRepository.php)app/Modules/Post/Dtos/PostDto.php)app/Modules/Post/Http/Requests/StorePostRequest.php, PostResource.php)routes/web.php or routes/api.php stubs)Register Module
Add the module to config/modules.php:
'Post' => \Modules\Post\PostServiceProvider::class,
Then publish the module:
php artisan module:publish Post
Use zapcraft:make for full-stack entity scaffolding:
php artisan zapcraft:make User --api --with-tests
--api: Generates API-specific resources (e.g., PostResource).--with-tests: Includes PHPUnit test stubs.Leverage nwidart/laravel-modules patterns:
app/Modules/{Entity}/.PostServiceProvider:
public function register()
{
$this->app->bind(
\Modules\Post\Repositories\PostRepositoryInterface::class,
\Modules\Post\Repositories\PostRepository::class
);
}
Extend default stubs by publishing and overriding:
php artisan vendor:publish --tag=zapcraft.stubs
Edit stubs in resources/views/vendor/zapcraft/stubs/.
PostRepositoryInterface into controllers:
public function __construct(PostRepositoryInterface $repository) {
$this->repository = $repository;
}
$dto = new PostDto($request->validated());
$this->repository->create($dto);
return PostResource::collection($this->repository->all());
Generated routes are stubs. Customize in routes/api.php:
Route::apiResource('posts', \Modules\Post\Http\Controllers\PostController::class)
->middleware('auth:api');
Use --with-tests flag to generate test stubs:
php artisan zapcraft:make Comment --with-tests
Test files appear in tests/Module/Comment/.
Module Autoloading
composer dump-autoload isn’t run after publishing.modules/ to composer.json autoload:
"autoload": {
"psr-4": {
"Modules\\": "app/Modules/"
}
}
Then run:
composer dump-autoload
Stub Overrides
resources/views/vendor/zapcraft/stubs/).config/zapcraft.php under stubs_path.Route Conflicts
routes/web.php or routes/api.php after generation.Repository Binding
ServiceProvider.register():
$this->app->bind(
\Modules\Post\Repositories\PostRepositoryInterface::class,
\Modules\Post\Repositories\PostRepository::class
);
DTO Validation
PostDto to include validation logic or use StorePostRequest for validation.php artisan config:clear
config/zapcraft.php to log generator output:
'debug' => env('ZAPCRAFT_DEBUG', false),
Custom Commands Extend the generator by creating a custom command:
php artisan make:command CustomZapcraftCommand
Extend HoldMyGlass\ZapCraft\Console\MakeEntityCommand.
Additional File Types Add new file templates by:
resources/views/vendor/zapcraft/stubs/custom/.config/zapcraft.php to include them in the generator.Dynamic Naming
Use --name or --singular flags to customize generated class names:
php artisan zapcraft:make "Blog Post" --singular
Seeding Integrate with Laravel’s seeder by extending the generator to include a seeder stub:
php artisan zapcraft:make Post --with-seeder
zapcraft:make command.--skip={migration,controller,...} to generate only needed files:
php artisan zapcraft:make User --skip=migration
How can I help you explore Laravel packages today?