PHPackages                             jeffersongoncalves/laravel-zero-console - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. jeffersongoncalves/laravel-zero-console

ActiveLibrary[CLI &amp; Console](/categories/cli)

jeffersongoncalves/laravel-zero-console
=======================================

Reusable traits for Laravel Zero commands: output formatting (tables, state colorization, dates), standardized API error handling, and cwd/argument path resolution.

v1.0.0(today)10MITPHPPHP ^8.2CI passing

Since Jun 23Pushed today1 watchersCompare

[ Source](https://github.com/jeffersongoncalves/laravel-zero-console)[ Packagist](https://packagist.org/packages/jeffersongoncalves/laravel-zero-console)[ Docs](https://github.com/jeffersongoncalves/laravel-zero-console)[ RSS](/packages/jeffersongoncalves-laravel-zero-console/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

[![laravel-zero-console](https://raw.githubusercontent.com/jeffersongoncalves/laravel-zero-console/main/art/jeffersongoncalves-laravel-zero-console.png)](https://raw.githubusercontent.com/jeffersongoncalves/laravel-zero-console/main/art/jeffersongoncalves-laravel-zero-console.png)

laravel-zero-console
====================

[](#laravel-zero-console)

Reusable traits for [Laravel Zero](https://laravel-zero.com) (and plain Laravel) commands. Extracted from real CLIs that kept copy-pasting the same helpers: output formatting, standardized API error handling, and path resolution.

Why
---

[](#why)

Every CLI ends up reimplementing the same chores: rendering tables that gracefully handle empty results, colorizing status strings, formatting dates, swallowing API exceptions into clean exit codes, and turning a `path` argument (or the cwd) into a real filesystem path. This package ships those as small, focused traits.

Installation
------------

[](#installation)

```
composer require jeffersongoncalves/laravel-zero-console
```

Requires PHP `^8.2` and `illuminate/console` `^11.0|^12.0`.

Traits
------

[](#traits)

### `FormatsOutput`

[](#formatsoutput)

Use inside an `Illuminate\Console\Command` (relies on `$this->table()` and `$this->components`).

```
use Illuminate\Console\Command;
use JeffersonGoncalves\LaravelZero\Console\FormatsOutput;

class ListCommand extends Command
{
    use FormatsOutput;

    public function handle(): int
    {
        // Renders a table, or "No results found." when $rows is empty.
        $this->renderTable(['ID', 'State', 'Updated'], $rows);

        $this->line($this->colorize('OPEN', $this->stateColor('OPEN'))); // OPEN
        echo $this->formatDate('2024-01-02 03:04:05');                   // 2024-01-02 03:04
        echo $this->formatDate(null);                                    // -

        return self::SUCCESS;
    }
}
```

Methods:

- `renderTable(array $headers, array $rows): void` — renders a table, or an info message when there are no rows.
- `colorize(string $value, string $color): string` — wraps a value in `...` tags.
- `stateColor(string $state): string` — case-insensitive lookup of a console color for a state.
- `stateColors(): array` — the state→color map. **Override it** to customize. The default merges pull-request states (`OPEN`, `MERGED`, `DECLINED`, `SUPERSEDED`) with issue-tracker states (`TODO`, `IN PROGRESS`, `DONE`).
- `formatDate(?string $date, string $format = 'Y-m-d H:i'): string` — formats a date string via `DateTime`; returns `-` for null/empty/invalid input.

Customizing the color map:

```
protected function stateColors(): array
{
    return [
        'SHIPPED' => 'magenta',
        'OPEN' => 'cyan',
    ];
}
```

### `HandlesApiErrors`

[](#handlesapierrors)

```
use JeffersonGoncalves\LaravelZero\Console\HandlesApiErrors;

class FetchCommand extends Command
{
    use HandlesApiErrors;

    public function handle(): int
    {
        return $this->handleApiErrors(function () {
            $data = $this->api->fetch(); // may throw any Throwable

            $this->renderTable(['ID'], $data);

            return self::SUCCESS;
        });
    }
}
```

- `handleApiErrors(callable $callback): int` — runs the callback; on success returns its int result (or `SUCCESS` when it returns null); on any `Throwable` prints the message via `$this->components->error()` and returns `FAILURE`.

### `ResolvesPath`

[](#resolvespath)

```
use JeffersonGoncalves\LaravelZero\Console\ResolvesPath;

$path = $this->resolvePath($this->argument('path')); // realpath, or cwd when empty
$cwd  = $this->resolveCwd();                          // realpath of getcwd()
```

- `resolvePath(?string $argument = null): string` — resolves an optional argument to its realpath, falling back to the cwd; returns the original input when the path does not exist.
- `resolveCwd(): string` — the current working directory resolved to its realpath.

Testing
-------

[](#testing)

```
composer install
composer test
```

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/411493?v=4)[Jefferson Gonçalves](/maintainers/jeffersongoncalves)[@jeffersongoncalves](https://github.com/jeffersongoncalves)

---

Top Contributors

[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

clicomposerconsolejeffersongoncalveslaravel-zerooutput-formattingphptraitscliconsolelaravel-zeroformattingtabletraits

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jeffersongoncalves-laravel-zero-console/health.svg)

```
[![Health](https://phpackages.com/badges/jeffersongoncalves-laravel-zero-console/health.svg)](https://phpackages.com/packages/jeffersongoncalves-laravel-zero-console)
```

###  Alternatives

[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k348.7M10.4k](/packages/nunomaduro-collision)[nunomaduro/laravel-console-menu

Laravel Console Menu is an output method for your Laravel/Laravel Zero commands.

815424.6k52](/packages/nunomaduro-laravel-console-menu)[nunomaduro/laravel-console-task

Laravel Console Task is a output method for your Laravel/Laravel Zero commands.

2592.3M13](/packages/nunomaduro-laravel-console-task)[nunomaduro/laravel-console-summary

A Beautiful Laravel Console Summary for your Laravel/Laravel Zero commands.

672.2M4](/packages/nunomaduro-laravel-console-summary)[nunomaduro/laravel-console-dusk

Laravel Console Dusk allows the usage of Laravel Dusk in Laravel/Laravel Zero artisan commands.

16357.3k8](/packages/nunomaduro-laravel-console-dusk)[mehrancodes/laravel-harbor

A CLI tool to Quickly create On-Demand preview environment for your apps.

10095.6k](/packages/mehrancodes-laravel-harbor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
