Installation:
composer require dwo/user-commands-bundle:@dev
Register the bundle in config/bundles.php:
Dwo\UserCommandsBundle\DwoUserCommandsBundle::class => ['all' => true],
First Use Case:
Run the list command to verify functionality:
php artisan dwo:user:list
User model (assumes Eloquent).Where to Look First:
src/Command/ in the bundle for core logic.config/user_commands.php (if provided) or check the bundle’s Resources/config/ for defaults.UserRepository or UserManager).php artisan dwo:user:create --name="John Doe" --email="john@example.com" --password="secure123"
--interactive flag).UserCreated events (if supported) or override the command class to add logic (e.g., send welcome email).php artisan dwo:user:update 1 --name="John Updated"
--field=value pairs for partial updates.php artisan dwo:user:list --limit=10 --sort=-created_at
--limit, --offset, and --sort for pagination/sorting.--filter=role:admin.User model by binding your model in AppServiceProvider:
public function register()
{
$this->app->bind(
\Dwo\UserCommandsBundle\Model\UserInterface::class,
\App\Models\User::class
);
}
User model with additional fields (e.g., avatar). Update the create/update commands by:
app/Console/Commands/CustomUserCreateCommand).handle():
public function handle()
{
parent::handle();
$this->user->avatar = $this->option('avatar');
$this->user->save();
}
$user = (new CreateUserCommand())
->setName('API User')
->setEmail('api@example.com')
->handle();
UserRepository or use a test database:
$this->artisan('dwo:user:create', [
'--name' => 'Test User',
'--email' => 'test@example.com',
'--password' => 'password',
])->assertExitCode(0);
No Default Config:
config/user_commands.php. Check for hardcoded values (e.g., password rules) in the command classes.php artisan vendor:publish --tag=user-commands-config
Model Assumptions:
User model with specific fields (name, email, password). Mismatches will cause errors.Interactive Mode Quirks:
--non-interactive flag or use --force for scripts.No Transaction Support:
DB::transaction():
DB::transaction(function () use ($user) {
$user->update($data);
// Other operations...
});
Password Handling:
Hash::make() and avoid logging sensitive data.Command Output:
php artisan dwo:user:create --verbose
handle() method of the command class.Database Issues:
users table matches the expected schema. Run:
php artisan schema:dump
to compare.Service Binding:
php artisan container:list | grep User
Events:
UserCreated, UserUpdated (if the bundle dispatches them). Add to EventServiceProvider:
protected $listen = [
\Dwo\UserCommandsBundle\Events\UserCreated::class => [
\App\Listeners\SendWelcomeEmail::class,
],
];
Custom Validators:
$this->app->bind(
\Dwo\UserCommandsBundle\Validator\UserValidator::class,
\App\Validators\CustomUserValidator::class
);
Console Output:
configure():
protected function configure()
{
parent::configure();
$this->tableHeaders = ['ID', 'Name', 'Email', 'Role'];
}
Localization:
php artisan vendor:publish --tag=user-commands-translations
Then add translations to resources/lang/.How can I help you explore Laravel packages today?