Installation
composer require drosalys/maker-bundle
Register the bundle in config/bundles.php (Symfony) or ensure it’s auto-discovered in Laravel (if ported).
First Use Case Run a basic command to generate a scaffold:
php artisan make:bundle-scaffold User
This creates a CRUD structure for a User entity with:
UserController)UserRepository)UserService)--with-migration flag is used)--with-tests flag is used)Where to Look First
php artisan to see available make:bundle-* commands.vendor/drosalys/maker-bundle/src/Resources/skeleton/ for default templates.config/maker-bundle.php (if available).Scaffold Generation
Use make:bundle-scaffold for full-stack CRUD:
php artisan make:bundle-scaffold Post --with-migration --with-tests --api
--api: Generates API-specific routes/controllers.--with-validation: Adds request validation rules.Modular Extensions Generate isolated components:
php artisan make:bundle-controller Admin/UserController
php artisan make:bundle-repository UserRepository
php artisan make:bundle-service UserService
Custom Templates Override default templates by copying skeleton files to:
resources/maker-bundle/skeleton/
Example: Modify controller.stub to add custom methods.
Integration with Existing Code
BaseRepository to add custom query methods.
class UserRepository extends BaseRepository
{
public function activeUsers()
{
return $this->model->where('active', true);
}
}
class UserService
{
public function __construct(private UserRepository $repository) {}
public function getActiveUsers()
{
return $this->repository->activeUsers()->get();
}
}
API Resources Generate API resources with:
php artisan make:bundle-api-resource UserResource
Customize fields in UserResource.php:
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
];
}
Testing
Use --with-tests to generate PHPUnit tests. Extend with custom assertions:
public function testCreateUser()
{
$response = $this->post('/api/users', ['name' => 'Test']);
$response->assertCreated();
$this->assertDatabaseHas('users', ['name' => 'Test']);
}
Namespace Conflicts
--namespace flag:
php artisan make:bundle-service UserService --namespace=App\Services\Admin
Migration Overwrites
--with-migration may overwrite existing ones. Backup first or use --force cautiously.Stub File Overrides
resources/maker-bundle/skeleton/ must match the original structure exactly. Misspelled placeholders (e.g., {{= }} vs {{ }}) will break generation.Laravel-Specific Quirks
Bundle classes) may need adaptation. Replace Bundle with ServiceProvider or remove unused traits.Dependency Injection
AppServiceProvider:
$this->app->bind(UserRepository::class, function ($app) {
return new UserRepository(new User());
});
Command Output
Run with -vvv for verbose output:
php artisan make:bundle-scaffold User -vvv
Helps identify template rendering issues.
Template Debugging
Add {{ dump($) }} to stub files to inspect variables during generation.
Cache Issues Clear Laravel’s command cache if changes to stubs aren’t reflected:
php artisan cache:clear
Partial Generation Generate only what you need to avoid clutter:
php artisan make:bundle-controller UserController --no-repository --no-service
Reusable Config
Define default options in config/maker-bundle.php (if supported):
'default_namespace' => 'App\\Bundles',
'use_api_resources' => true,
Post-Generation Hooks
Use Laravel’s generated:bundle event (if supported) to run post-processing:
// In EventServiceProvider
protected $listen = [
'generated:bundle' => [
'App\Listeners\PostBundleGeneration',
],
];
Documentation Since the package lacks formal docs, explore:
tests/ directory of the package.Performance For large projects, generate bundles in batches to avoid long build times. Example:
php artisan make:bundle-scaffold Post --no-tests
php artisan make:bundle-tests Post
How can I help you explore Laravel packages today?