Installation:
composer require norman-huth/muetze-site
Publish the config file if you need to customize defaults:
php artisan vendor:publish --provider="NormanHuth\Muetze\SiteServiceProvider" --tag="config"
First Use Case:
Create a pivot table migration for a many-to-many relationship (e.g., User and Role):
php artisan make:migration:pivot User Role
This generates a migration with timestamps and foreign keys for both models.
Create a full CRUD bundle (model + migration + policy + resource):
php artisan make:bundle Post
This leverages Laravel's built-in scaffolding but bundles it into a single command.
Standard Usage:
Use make:migration:pivot to quickly scaffold pivot tables for polymorphic or standard many-to-many relationships.
Example:
php artisan make:migration:pivot User Role --id1=uui --id2=foo_bar
id.{Model1}{Model2} (e.g., UserRole).Integration Tip:
Pair with Laravel’s belongsToMany() to define relationships in models:
public function roles()
{
return $this->belongsToMany(Role::class, 'user_role');
}
Default Behavior:
The make:bundle command generates:
--m flag)--m flag)--p flag)--r flag)--c flag)--a flag)Example (custom bundle):
php artisan make:bundle Product --n --m --p --r --c
--n forces Nova resource creation (if enabled in config).--m, --p, --r, etc., override config defaults.Customization:
Modify config/muetze.php to set global defaults (e.g., disable migrations by default):
'make-bundle' => [
'migration' => false,
// ... other flags
]
Integration Tips:
--r to generate a web resource (for Laravel UI) alongside the model.--a to generate an API resource (for API-heavy projects).make:auth or make:seeder for additional scaffolding.Custom Commands: Extend the package by creating your own Artisan commands that reuse its logic (e.g., custom pivot table naming conventions). Example:
php artisan make:command CustomPivotCommand
Then integrate the pivot migration logic from Muetze\Commands\MakePivotTable.
Configuration Overrides: Override the published config to:
controller namespace).Archived Package:
Config Overrides:
vendor:publish) means using hardcoded defaults.nova-resource is false in config but you run make:bundle --n, it will fail silently.Pivot Table Naming:
{Model1}{Model2}. Override in the migration if needed:
public function up()
{
Schema::create('custom_user_role', function (Blueprint $table) { ... });
}
Policy Conflicts:
--p flag creates a basic policy. Ensure it doesn’t conflict with existing policies (e.g., UserPolicy vs. PostPolicy).Command Errors:
make:migration:pivot:
php artisan make:migration:pivot NonExistentModel Role
→ Fails with Class not found (helpful for catching typos).Bundle Generation:
make:bundle skips expected files, verify the config:
php artisan config:get muetze.make-bundle
--verbose to debug:
php artisan make:bundle Post --verbose
Namespace Issues:
config/muetze.php under 'namespaces'.Custom Stubs:
vendor/norman-huth/muetze/src/stubs) by publishing them:
php artisan vendor:publish --provider="NormanHuth\Muetze\SiteServiceProvider" --tag="stubs"
model.stub, policy.stub, etc., to match your team’s conventions.Add New Features:
MakeBundle command to support additional scaffolding (e.g., factories, observers):
// In a service provider:
$this->app->extend('command.make.bundle', function ($command) {
$command->addOption('factory', 'Create a factory', 'factory');
return $command;
});
Testing:
php artisan migrate
$user->roles()->attach([1, 2]);
How can I help you explore Laravel packages today?