PHPackages                             lsrur/codeblade - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. lsrur/codeblade

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lsrur/codeblade
===============

A handy and powerful code generator for Laravel

14171PHP

Since Mar 13Pushed 4y ago2 watchersCompare

[ Source](https://github.com/lsrur/codeblade)[ Packagist](https://packagist.org/packages/lsrur/codeblade)[ RSS](/packages/lsrur-codeblade/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

A handy and powerful code generator for Laravel
===============================================

[](#a-handy-and-powerful-code-generator-for-laravel)

As programmers we always face the tedious need to write repetitive code for different models or tables of our application. As a code generator, CodeBlade will relieve you of that boredom but with two big differences from other similar tools:

- CodeBlade does not require you to write and maintain definition files (json, yaml or any other metadata file), instead it reverse-engineers your database on the fly and exposes a data dictionary to your templates for code generation.
- CodeBlade let you write your own templates in pure Blade! Yes, the power of Laravel Blade generating Laravel components such as models, controllers, views, seeders, factories, form requests... but also Vue, React, Livewire, html or any source code you need, just write the template with the Blade syntax you already know.

> Code Blade is at an early stage, please tell me about your experience installing and getting started with it.

Table of Contents
-----------------

[](#table-of-contents)

1. [Requirements](#requirements)
2. [Instalation](#instalation)
3. [Configuration](#config)
4. [Code generation](#codegen)
5. [Writing templates](#writing)
    1. [Table Properties](#table_object)
    2. [Field Properties](#field_object)
    3. [Relation Properties](#relation_object)
    4. [Directives](#directives)
    5. [Examples](#samples)
6. [Contributing](#contrib)
7. [Security](#security)
8. [License](#license)

Requirements
----------------------------------------------------

[](#requirements)

- Laravel 9+ (CodeBlade uses a new feature in Laravel 9 for inline compilation of Blade templates).
- MySQL (For now, CodeBlade only works with MySQL/MariaDB connections. Reverse engineering for pgsql is on the way).

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

[](#installation)

You can install the package via composer:

```
composer require lsrur/CodeBlade

```

Publish the configuration file (it will be useful):

```
php artisan vendor:publish --provider="Lsrur\Codeblade\CodebladeServiceProvider"

```

Prepare the templates folder in your project and copy the examples:

```
php artisan codeblade:install

```

Configuration
-----------------------------------------------

[](#configuration)

There are two configuration keys in config/CodeBlade.php:

KeyDescriptiontemplate\_foldersArray of folders where to look for the templates. You can include a shared template folder located outside your project.pbcopy\_commandShell command for copying file contents to the clipboard (as pbcopy is for linux/osx)Code generation
--------------------------------------------------

[](#code-generation)

```
php artisan codeblade:make   --params= --force --copy

```

ParamDescriptiontemplateTemplate file in dot notation (samples.controller), it should exist in one of your template folders/subfolders defined in the configurationtable1,table2One or multiple table names (separated by commas) to be parsed and passed to the generator--params=Parameters to be passed to the template (see below)--copyCopy output code to the clipboard instead of writing files--forceOerwrite output files without asking### Template parameters

[](#template-parameters)

CodeBlade allows you to specify one or multiple (comma separated with no spaces) parameters that will be passed to the template:

```
php artisan codeblade:make mytemplate mytable --params=flag,foo=bar

```

Those parameters will be usable from the template as follows:

```
@if($params->flag)
  flag is ON
@endif

@if(! $params->noexist)
  noexist is OFF or does not exists
@endif

{{$params->foo}}
// Result 'bar'

@foreach($params->all as $key=>$value)
  {{$key}}
@endforeach
// Result flag foo
```

Writing templates
----------------------------------------------------

[](#writing-templates)

Every time we execute a "make" command, CodeBlade reverse-engineers the tables involved, creating a data dictionary which passes to the code generation template in the form of a Table object. Then we write our templates as follows:

```
@forarch($table->fields as $field)
  @if(! $field->is_autoincrement)
    {{$field->camel()->prepend('$')}} = $request->{{$field->name}};
  @endif
@endforeach
```

### Table Properties

[](#table-properties)

PropertyDescriptionnameName of the table as Stringable instance [(see stringables)](#stringables)modelInferred model name based on Laravel naming conventionsfieldsArray of Field objectsprimaryArray of primary keys as Field objectsrelationsArray of Relation objects###  Field Properties

[](#-field-properties)

PropertyDescriptionnameName of the field as Stringable instance [(see stringables)](#stringables)primaryThe field is primary key (boolean)autoincrementThe field is autoincrement (boolean)indexThe field has an index (boolean)defaultDefault value (any)nullableField is nullable (boolean)base\_typeThe base type [(see base types)](#base_types)typeField typesizeField size or total digitsscaleDecimal digitsenum\_optionsArray of options if field type is enum or setis\_foreignField is foreignreferencesReferenced table as Stringable [(see stringables)](#stringables)onReferenced key on foreign tableruleInferred validation rule based on field properties (type, size, foreign, nullable, etc.) \*fakerInferred faker method ased on field type and foreign properties \*castCast type (Ex: json-&gt;array) \*custom\_property[see custom properties below](#custom_props)\* These properties can be overridden by custom\_properties

#### Base types

[](#base-types)

Base types are useful for grouping fields of similar -but not the same- data types.

```
@foreach($Table->fields as $field)
  @includeIf($field->base_type == 'string', 'partials.forms.textinput');
  @includeIf($field->base_type == 'integer', 'partials.forms.integerinput');
@endforeach
```

MySQL Field typeBase typechar, varcharstringtext, longtext, tinytext, mediumtexttextint, smallint, mediumint, bigintintegertinyintbooleanfloat, decimal, doubledecimaldatedatedatetime, timestampdatetimeblob, binary, longblob, mediumblob, tinyblob, varbinarybinaryenumenumsetsetjson, jsonbjson#### Custom properties

[](#custom-properties)

CodeBlade will parse the "comment" metadata of each field looking for custom properties. You can add these properties in the field definition during migration in the following way:

```
...
Schema::create('contacts', function (Blueprint $table) {
  $table->string("company_name")
     ->comment("faker=company(),flag,foo=bar");
...
```

Then those properties will be available in your templates as direct properties of each field.

```
@foreach($tabe->fields as $field)
  @if($field->flag)
    // 'flag' will be true for company_name
  @endif

  @if($field->foo == 'bar')
    //
  @endif

  ${{$field->name->camel()}} = faker()->{{$field->faker}};
  // result: $companyName = faker()->company();

@endforeach
```

### Relation Properties

[](#relation-properties)

PropertyDescriptionlocal\_keyLocal referenced field nametype'belongs\_to\_many' or 'has\_many'pivotPivot table name for 'belongs\_to\_many'modelRelated model name based on Laravel naming conventionsforeign\_keyRelated foreign key for 'has\_many'foreign\_tableRelated foreign table for 'has\_many'#### Stringables

[](#stringables)

Properties returned as Stringable instances can be used as-is or by chaining \\Str methods:

```
{{$Table->name}}
// contacts

{{$Table->name->singular()->title()->append('Controller'}}
// ContactController

@foreach($Table->fields as $field)
  {{$field->name->camel()->prepend('$')}} = $request->{{$field->name}};
  // $companyName = $request->company_name;
@endforeach
```

### Blade Directives

[](#blade-directives)

##### @cbSaveAs()

[](#cbsaveas)

Tells CodeBlade where to write the generated code. If a template does not specify this directive, the resulting code will be copied to the clipboard.

```
@cbSaveAs(app_path('Http/Controllers/'.$table->model.'Controller.php'))
// for table "contacts", the file will be written in app/Http/Controllers/ContactController.php

```

##### @cbRun()

[](#cbrun)

Tells CodeBlade to execute another template, same tables and parameters will be applied.

```
{{-- This is a CRUD template --}}
@cbRun('model')
@cbRun('controller')
@cbRun('edit_view')
@cbRun('create_view')
@cbRun('index_view')
```

##### @cbCurly()

[](#cbcurly)

Wraps the output in curly braces, useful when generating Blade or Vue views.

```
@cbCurly({{$table->name->singular()->prepend('$')}}->{{$field->name}})
=> {{$contact->company_name}}

@cbCurly({{$table->name->singular()}}.{{$field->name}})
=> {{contact.company_name}}
```

### Example Templates

[](#example-templates)

Take a look at the [samples](https://github.com/lsrur/CodeBlade/tree/master/samples) folder of this repo. In order not to interfere with your project, the template examples provided generate code in `yourprojectroot/generatedcode` folder. Change the cbSaveAs line in the templates to write in the appropriate project folders.

The examples are provided to guide you in developing your own templates, they are not admin panel builders or anything like that.

Contributing
-----------------------------------------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------------------------------------------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
------------------------------------------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a30626359de40bdadeb89ec8b80054e89adb37e833d4e5b6ce52e058dee6517f?d=identicon)[lautarosrur](/maintainers/lautarosrur)

---

Top Contributors

[![lsrur](https://avatars.githubusercontent.com/u/7329922?v=4)](https://github.com/lsrur "lsrur (1 commits)")

### Embed Badge

![Health badge](/badges/lsrur-codeblade/health.svg)

```
[![Health](https://phpackages.com/badges/lsrur-codeblade/health.svg)](https://phpackages.com/packages/lsrur-codeblade)
```

###  Alternatives

[melbahja/seo

SEO library for PHP is a simple PHP library to help developers 🍻 do better on-page SEO optimizations.

367157.6k9](/packages/melbahja-seo)[ctidigital/magento2-configurator

Keep magento persistently configured using files

174354.6k](/packages/ctidigital-magento2-configurator)[scriptfusion/byte-formatter

Formats byte values as human-readable strings.

46336.0k7](/packages/scriptfusion-byte-formatter)[elhebert/laravel-sri

Subresource Integrity hash generator for laravel

39250.5k](/packages/elhebert-laravel-sri)[novaway/feature-flag-bundle

Very KISS bundle to manage features flag

25291.0k](/packages/novaway-feature-flag-bundle)[b13/bolt

Bolt - An easy TYPO3 integration basis

28211.3k2](/packages/b13-bolt)

PHPackages © 2026

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