Installation
composer require vizrex/laraviz
Add the package to providers in config/app.php if not auto-discovered.
First Use Case: Extending a Command
Create a new Artisan command extending Vizrex\Laraviz\Console\BaseCommand:
use Vizrex\Laraviz\Console\BaseCommand;
class MyCommand extends BaseCommand
{
protected $signature = 'my:command';
protected $description = 'My custom command';
public function handle()
{
$this->debug('Debug message (visible only with -vvvv)');
$this->info($this->str('key.in.translation'));
}
protected function setNamespace()
{
$this->namespace = 'commands';
}
protected function setDefaultTranslationFile()
{
$this->defaultTranslationFile = 'my-command';
}
}
Where to Look First
BaseCommand in vendor/vizrex/laraviz/src/Console/BaseCommand.php for core methods.BaseServiceProvider for getNamespace() implementation patterns.resources/lang/{locale}/my-command.php for translation files.Command Development
BaseCommand for all CLI tools.setNamespace() to align with your package’s translation namespace (e.g., 'vizrex/my-package').setDefaultTranslationFile() to define the base translation file (e.g., 'my-package').debug() for verbose logging (visible only with -vvvv).str() for localized strings (auto-falls back to __() or trans()).Translation Management
resources/lang/{locale}/{translation-file}.php.resources/lang/en/my-command.php
resources/lang/es/my-command.php
$this->str('key.in.my-command').Service Provider Integration
BaseServiceProvider to centralize namespace logic:
class MyServiceProvider extends BaseServiceProvider
{
public static function getNamespace(): string
{
return 'vizrex/my-package';
}
}
setNamespace().Verbose Debugging
debug() for conditional logging:
$this->debug('Detailed debug info', ['var' => $variable]);
-vvvv to see output.vizrex/laraviz as a dependency and enforce BaseCommand/BaseServiceProvider in your package’s docs.debug() output in tests by checking $command->output->verbose() or $command->output->wrapped().Namespace Mismatches
setNamespace() and BaseServiceProvider::getNamespace() return mismatched values, translations will fail to load.Translation File Not Found
setDefaultTranslationFile() is missing or misconfigured, str() will throw an error.setDefaultTranslationFile() and verify the file exists in resources/lang/.Verbose Mode Ignored
debug() output won’t appear unless -vvvv is used.Static Method Dependencies
BaseServiceProvider::getNamespace() is static, so it cannot access instance properties.-v: Normal output.-vv: More verbose.-vvv: Debug output.-vvvv: debug() output.$this->debug('Loaded translations:', [
'keys' => config('app.locale'),
'files' => $this->defaultTranslationFile,
]);
handle():
$this->debug('Namespace:', [$this->namespace]);
Customize debug()
Override the method to add timestamps or log levels:
protected function debug($message, array $context = [])
{
if ($this->option('verbose')) {
$this->line('<comment>[' . now()->format('H:i:s') . ']</comment> ' . $message);
}
}
Add Translation Fallbacks
Extend str() to support fallback locales:
protected function str($key, array $replace = [], $locale = null)
{
$locale = $locale ?: app()->getLocale();
return trans("{$this->namespace}::{$this->defaultTranslationFile}.{$key}", $replace, $locale);
}
Dynamic Translation Files Load translation files dynamically based on runtime conditions:
protected function setDefaultTranslationFile()
{
$this->defaultTranslationFile = 'dynamic-' . request()->input('type');
}
Integration with Laravel Mix
Use debug() to log asset compilation steps:
$this->debug('Compiling assets for environment: ' . config('app.env'));
How can I help you explore Laravel packages today?