PHPackages                             drewlabs/g-cli - 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. drewlabs/g-cli

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

drewlabs/g-cli
==============

Generates classes, services, models and controller's components or entire project source code from databse structure

v0.3.56(1y ago)0134MITPHPPHP &gt;=7.4

Since May 31Pushed 1w ago1 watchersCompare

[ Source](https://github.com/azlabsphp/gcli)[ Packagist](https://packagist.org/packages/drewlabs/g-cli)[ RSS](/packages/drewlabs-g-cli/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (16)Versions (51)Used By (0)

GCli
====

[](#gcli)

This project uses the code generator package to create components like controllers, services, models etc for laravel projects...

Usage
-----

[](#usage)

### Programming API

[](#programming-api)

This section present you with PHP classes API for creating controllers, Services, Model, ViewModel and Data Transfert Object

#### The Controller Builder

[](#the-controller-builder)

This package provide you with a controller class builder that can be used to build a resource controller, an invokable controller or a pre-made CRUD controller.

```
// ...
use function Drewlabs\GCli\Proxy\ComponentsScriptWriter;
use function Drewlabs\GCli\Proxy\MVCControllerBuilder;
// ...

// This code creates an invokable controller
ComponentsScriptWriter(__DIR__ . '/examples/src')->write(
    (MVCControllerBuilder())
        ->bindServiceClass(
            "App\\Services\\PersonsService"
        )
        ->asInvokableController()
        ->build()
);

// This code creates a resource controller and bind it to a model
// If conroller name is not provided, it's generated from the model name
ComponentsScriptWriter(__DIR__ . '/examples/src/')->write(
    (MVCControllerBuilder('PostsController', '\\App\\Http\\Controllers\\Common'))
        ->bindServiceClass(
            "App\\Services\\PersonsService"
        )
        ->build()
)
```

#### Service class builder

[](#service-class-builder)

A service is like a delegate that handle controller action and has access to the database model.

You can create a service that provides empty implementation or is pre-filled with CRUD operations.

```
// ...
use function Drewlabs\GCli\Proxy\ComponentsScriptWriter;
use function Drewlabs\GCli\Proxy\MVCServiceBuilder;
// ...

// Creating a prefilled service with name derived from a model class name
ComponentsScriptWriter(__DIR__ . '/examples/src/')->write(
    (MVCServiceBuilder())
        ->bindModel(
            "App\\Models\\Human"
        )
        ->asCRUDService()
        ->build()
)

// Creates a simple service with only a handle method
ComponentsScriptWriter(__DIR__ . '/examples/src/')->write(
    (MVCServiceBuilder())
        ->bindModel(
            "App\\Models\\Person"
        )
        ->build()
)
```

#### View Model class builder

[](#view-model-class-builder)

A view model is a class that wrap arround user provided values, validation rules and if possible a reference to the authenticated user.

```
// ...
use function Drewlabs\GCli\Proxy\ComponentsScriptWriter;
use function Drewlabs\GCli\Proxy\ViewModelBuilder;
// ...

// Creating a fully complete view model
ComponentsScriptWriter(__DIR__ . '/examples/src/')->write(
    (ViewModelBuilder())
        ->bindModel(
            "App\\Models\\Person"
        )
        ->addInputsTraits()
        ->addFileInputTraits()
        ->addAuthenticatableTraits()
        ->setRules([
            'firstname' => 'required|max:50',
            'lastname' => 'required|max:50'
        ])
        ->build()
);

// Create a view model that can only be used with the validator to validate user input
ComponentsScriptWriter(__DIR__ . '/examples/src/'))->write(
    (ViewModelBuilder())
        ->bindModel(
            "App\\Models\\Person"
        )
        ->asSingleActionValidator()
        ->setRules([
            'firstname' => 'required|max:50',
            'lastname' => 'required|max:50'
        ])
        ->build()
)
```

#### Model class builder

[](#model-class-builder)

A database model is like en entity manager class that interact with database on your behalf. They packahe provides an implementation of the Eloquent ORM model.

This implementation use the drewlabs/database package for the builder and it suppose that package is install as dependency. You are free to provide an implementation of your on builder.

```
// ....
use function Drewlabs\GCli\Proxy\ComponentsScriptWriter;
use function Drewlabs\GCli\Proxy\EloquentORMModelBuilder;
use function Drewlabs\GCli\Proxy\ORMColumnDefinition;
use function Drewlabs\GCli\Proxy\ORMModelDefinition;
//...

// Building a model
ComponentsScriptWriter(__DIR__ . '/examples/src'))->write(EloquentORMModelBuilder(ORMModelDefinition([
    'primaryKey' => 'id',
    'name' => null,
    'table' => 'persons',
    'columns' => [
        ORMColumnDefinition([
            'name' => 'firstname',
            'type' => 'string'
        ]),
        ORMColumnDefinition([
            'name' => 'lastname',
            'type' => 'string'
        ])
    ],
    'increments' => false,
    'namespace' => "App\\Models"
]))->build()

// To build a model as a view model
ComponentsScriptWriter(__DIR__ . '/examples/src')->write((EloquentORMModelBuilder(ORMModelDefinition([
    'primaryKey' => 'id',
    'name' => null,
    'table' => 'humans',
    'columns' => [
        ORMColumnDefinition([
            'name' => 'firstname',
            'type' => 'string'
        ]),
        ORMColumnDefinition([
            'name' => 'lastname',
            'type' => 'string'
        ])
    ],
    'increments' => false,
    'namespace' => "App\\Models"
])))->asViewModel()->build();
```

Laravel Commands interfaces
---------------------------

[](#laravel-commands-interfaces)

The package offers some laravel framework commands for easily creating component from your terminal application. Those commands are:

### drewlabs:mvc:create command

[](#drewlabsmvccreate-command)

This command allow devolpper to generate an entire api stack from database tables, with a pre-defined structure. The generated output is configurable using artisan command interface input:

- Creating mvc component along with controllers and routes

```
php artisan drewlabs:mvc:create --http
```

#### Disabling caching

[](#disabling-caching)

By default the command use caching to optimize the task when generating more than once required components. using the command below, the command will ignore the cache and re-generate previously generated files:

```
php artisan drewlabs:mvc:create --http --force
```

#### Removing schema prefix

[](#removing-schema-prefix)

In some application, databases are prefixed using schema name. Generated code will mostly add the schema prefix to classes and interfaces. To prevent such output, developper can use `--schema` option to allow the tell the command to trim the schema part from generated classes:

```
php artisan drewlabs:mvc:create --http --schema=test
```

#### Adding middleware

[](#adding-middleware)

Sometimes developpers might want to group generated routes in a given middleware. The command interface provide an option to specify the middleware to use when grouping generated route using:

```
php artisan drewlabs:mvc:create --http --middleware=auth
```

#### Table filters

[](#table-filters)

The command interface also support an `--only` option wich allow developpers to specify the list of table to include when generating code:

```
php artisan drewlabs:mvc:create --http --only=users
```

**Warning** The `--only` option is in an experimental status, and as it can rewrite your routing file removing previously generated routes.

#### Setting route file name

[](#setting-route-file-name)

By default the routing file name used by the command is `web.php` located in the /routes directory of the laravel project. To override the default:

```
php artisan drewlabs:mvc:create --http --routingfilename=api.php
```

The command above use or create a file in the project /routes directory for routing.

#### Model relations

[](#model-relations)

`drewlabs:mvc:create` provides a flag for generating relation method definition while generating model class definition. Using `--relations` flag, developpers can generate model with corresponding `relations`.

```
php artisan drewlabs:mvc:create --http --relations
```

**FAQ** How can model relation methods can be customized ?

The command support argument for model relation customization. using `--manytomany`, `--toones`, `--manythroughs`, `--onethroughs`, developpers are able to specify relation that are `many to many`, `one to one`, `many through` and `one through` relation respectively.

The syntax for various customization are:

- `manytomany``source_table->pivot_table->destination_table:method`

```
php artisan drewlabs:mvc:create --http --relations --manytomany=posts->post_comments->comments --manytomany=posts->post_tags->tags
```

**Note** `[method]` part of the syntax can be omitted and will be generated by the command.

- `toones``source_table->destination_table:method`

```
php artisan drewlabs:mvc:create --http --relations --toones=employees->employee_managers
```

**Note** `[method]` part of the syntax can be omitted and will be generated by the command.

- `onethroughs` &amp; `manythroughs``source_table->pivot_table->destination_table:method`

**Note** `[method]` part of the syntax can be omitted and will be generated by the command.

```
php artisan drewlabs:mvc:create --http --relations --manythroughs=post_types->posts->comments:comments
```

#### Policy &amp; Guard

[](#policy--guard)

From version `2.9`, `drewlabs:mvc:create` command suport flag for adding policy guard definition to your project with default to allowing every controller action using `authorize` method. To generate policy classes use the `--policies` flag when running command.

**Note** A service provider class `[\App\Providers\PoliciesServiceProvider::class]` class is generated at the end of the command output. Please add it to let laravel know how to guard your model classes using generated policies.

```
php artisan drewlabs:mvc:create --http --policies
```

**Note**To preview the list of available options, please use the `php artisan drewlabs:mvc:create --help`

### Create a database model

[](#create-a-database-model)

```
# Create a database model
php artisan drewlabs:mvc:make:model --table=comments --columns="label|string" --columns="description|text" --columns="likes|number" --hidden=likes --path=src --namespace="\\Application\\Models" --appends=posts
```

### Create a php class

[](#create-a-php-class)

**Note** Use `php artisan drewlabs:mvc:make:class --help` command view the list of option available

```
php artisan drewlabs:mvc:make:class --path='src' --name=Post

```

### Create a data transfert object

[](#create-a-data-transfert-object)

**Note** Use `php artisan drewlabs:mvc:make:dto --help` command view the list of option available

```
php artisan drewlabs:mvc:make:dto --path=src --namespace=\\Application\\Dto
```

### Create a MVC service

[](#create-a-mvc-service)

**Note** Use `php artisan drewlabs:mvc:make:service --help` command view the list of option available

```
php artisan drewlabs:mvc:make:service --model=\\Application\\Models\\Comment --asCRUD --path=src
```

### Create a MVC view model

[](#create-a-mvc-view-model)

**Note** Use `php artisan drewlabs:mvc:make:viewmodel --help` command view the list of option available

```
php artisan drewlabs:mvc:make:viewmodel --model=\\Application\\Models\\Comment --single --path=src
```

### Create a MVC controller

[](#create-a-mvc-controller)

**Note** Use `php artisan drewlabs:mvc:make:controller --help` command view the list of option available

```
php artisan drewlabs:mvc:make:controller --name=Posts --path=src --model="\\Application\\Models\\Comment"
```

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance74

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~13 days

Recently: every ~5 days

Total

50

Last Release

465d ago

PHP version history (3 changes)v0.2.2PHP &gt;=7.2

v0.2.70PHP ^7.2|^8.0

v0.3.40PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c4973d500c7f4233d5ceacab51a57208d5fb60b0f95ae60264cf92380d0534?d=identicon)[azandrew-sidoine](/maintainers/azandrew-sidoine)

---

Top Contributors

[![azandrew-sidoine](https://avatars.githubusercontent.com/u/23530515?v=4)](https://github.com/azandrew-sidoine "azandrew-sidoine (265 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/drewlabs-g-cli/health.svg)

```
[![Health](https://phpackages.com/badges/drewlabs-g-cli/health.svg)](https://phpackages.com/packages/drewlabs-g-cli)
```

###  Alternatives

[silverstripe/framework

The SilverStripe framework

7313.7M2.8k](/packages/silverstripe-framework)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k17.8k](/packages/prestashop-prestashop)[showdoc/showdoc

ShowDoc is a tool greatly applicable for an IT team to share documents online

12.8k7.1k](/packages/showdoc-showdoc)[illuminate/console

The Illuminate Console package.

13046.0M6.5k](/packages/illuminate-console)

PHPackages © 2026

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