A Laravel package generator that creates packages with a custom code style and structure. This tool helps you quickly scaffold Laravel packages with models, controllers, services, and frontend components.
- Generate composer packages or domain-specific implementations
- Create models with fillable fields and casts
- Generate migrations with proper schema definitions
- Create controllers with resource methods
- Implement service layer for business logic
- Generate form requests with validation rules
- Create API resources for response formatting
- Generate Vue components for frontend (optional)
- Support for field management (add, update, remove)
- Customizable templates and configurations
You can install the package via composer:
composer require knausdev/package-generatorOr develop it locally:
# Create a packages directory in your Laravel project
mkdir -p packages/knausdev/package-generator
# Clone this repository into the directory or create files manually
git clone https://github.com/your-username/laravel-package-generator.git packages/knausdev/package-generator
# Add to composer.json repositories
"repositories": [
{
"type": "path",
"url": "./packages/knausdev/package-generator"
}
]
# Require the package
composer require knausdev/package-generatorAfter installation, run the setup command:
php artisan knausdev:installThis will:
- Create necessary directories (packages, domains)
- Generate route registration files
- Update main route files to include domain routes
- Publish configuration files
php artisan vendor:publish --provider="KnausDev\PackageGenerator\PackageGeneratorServiceProvider" --tag="package-generator-config"You can publish and customize the stub templates:
php artisan knausdev:publish-stubsThis will copy all stub templates to stubs/vendor/knausdev/package-generator where you can modify them to match your coding style.
php artisan knausdev:make-package YourPackageNameOptions:
--type=composer- Package type (composer or domain), default: composer--namespace=YourNamespace- The namespace of the package, default: KnausDev--path=/custom/path- Optional custom path for package--model=CustomModel- Optional model name (default derives from package name)--api-only- Whether the package is API only (no frontend)--api-version=v2- API version to use, default: v1
php artisan knausdev:package-model YourPackageName NewModelNameOptions are the same as for make-package.
# Add a field
php artisan knausdev:package-field add YourPackageName ModelName
# Update a field
php artisan knausdev:package-field update YourPackageName ModelName --field=fieldName
# Remove a field
php artisan knausdev:package-field remove YourPackageName ModelName --field=fieldNameDomain packages don't use the standard Laravel migration discovery. Use our custom command to run migrations:
# Run migrations for all domains
php artisan knausdev:domain-migrate
# Run migrations for a specific domain
php artisan knausdev:domain-migrate YourDomainName
# Fresh migrations (wipes database)
php artisan knausdev:domain-migrate --fresh
# With seeding
php artisan knausdev:domain-migrate --seedDomain routes aren't automatically registered. Use our command to generate a registration file:
php artisan knausdev:domain-routesThis command scans all domain packages for route files and generates:
routes/domain_web.php- For web routesroutes/domain_api.php- For API routes
Then add these lines to your main route files:
In routes/web.php:
require base_path('routes/domain_web.php');In routes/api.php:
require base_path('routes/domain_api.php');This package supports two types of package structures:
packages/knausdev/package-name/
├── composer.json
├── src/
├── ...
domains/KnausDev/DomainName/
├── composer.json # Automatically created to handle autoloading
├── Models/
├── Http/
├── ...
In domain packages, the namespace follows this structure:
- Domain:
KnausDev\DomainName - Controller:
KnausDev\DomainName\Http\Controllers\SomeController
For example, a User domain would have the namespace KnausDev\User\ and be located at domains/KnausDev/User/.
Each domain package automatically gets a composer.json file that configures PSR-4 autoloading for that domain. This autoloading is enabled by the Wikimedia Composer Merge Plugin, which is automatically configured when you run php artisan knausdev:install.
The generator supports the following field types:
string- String with customizable lengthinteger- Integer with optional min/max valuestext- Text field with optional rich editorboolean- Boolean (true/false) valuesfloat- Decimal numbers with configurable precisionfile- File uploads with customizable validation
Contributions are welcome! Please feel free to submit a Pull Request.
The MIT License (MIT). Please see License File for more information.