PHPackages                             webfactor/laravel-generators - 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. webfactor/laravel-generators

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

webfactor/laravel-generators
============================

Laravel generators for quickly creating entities.

3.3.6(6y ago)3011.1k5[2 issues](https://github.com/webfactor/laravel-generators/issues)[1 PRs](https://github.com/webfactor/laravel-generators/pulls)MITPHPPHP ~7.1CI failing

Since Mar 16Pushed 6y ago5 watchersCompare

[ Source](https://github.com/webfactor/laravel-generators)[ Packagist](https://packagist.org/packages/webfactor/laravel-generators)[ Docs](https://github.com/webfactor/laravel-generators)[ RSS](/packages/webfactor-laravel-generators/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (10)Dependencies (4)Versions (31)Used By (0)

laravel-generators
==================

[](#laravel-generators)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3690852511c445b83aae91d1bb855d95aaf3d7cd194c04bc446fc3fe83093890/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776562666163746f722f6c61726176656c2d67656e657261746f72732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webfactor/laravel-generators)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![StyleCI](https://camo.githubusercontent.com/eb7a085318f1b27df4d0542f194a8ab0d39c63820b080e00daa9a49047c2069b/68747470733a2f2f7374796c6563692e696f2f7265706f732f3132353537343630332f736869656c64)](https://styleci.io/repos/125574603)[![Build Status](https://camo.githubusercontent.com/692b582b86a7e0b3cae9709ea8f40a7b05b97d47c23089d5c67c26f8a6767888/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776562666163746f722f6c61726176656c2d67656e657261746f72732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/webfactor/laravel-generators)[![Coverage Status](https://camo.githubusercontent.com/276904c8d38b2ebb0dc098b15eece828ab540283478716dc19ec8841ecec459f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f776562666163746f722f6c61726176656c2d67656e657261746f72732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/webfactor/laravel-generators/code-structure)[![Quality Score](https://camo.githubusercontent.com/d08a7346e24b2ea9d13505212ae139c5af0cff03646d2986add4047ac5173d49/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776562666163746f722f6c61726176656c2d67656e657261746f72732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/webfactor/laravel-generators)[![Total Downloads](https://camo.githubusercontent.com/133ab1d0c9ab406434e74d54f0d4494a3facd6593f1052e3f2c8443a9b19f130/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776562666163746f722f6c61726176656c2d67656e657261746f72732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webfactor/laravel-generators)

This is a package developed by us for internal use. It is supposed to help us during development and save plenty of time by automating many steps while creating typical CRUD entities with [Laravel Backpack](https://laravel-backpack.readme.io/docs). You can write your own Services (they have to implement `Webfactor\Laravel\Generators\Contracts\ServiceInterface`) and register them in the `generators.php` config file, or use this package as an inspiration for your own implementation.

Install
-------

[](#install)

### Via Composer

[](#via-composer)

This package is indended to be used only for development, not for production. Because of that we recommend to use `require-dev`:

```
composer require --dev webfactor/laravel-generators
```

Usage
-----

[](#usage)

```
php artisan make:entity {entity_name} {--schema=} {--migrate} {--ide=} {--git}
```

- `entity_name`: Recommendation: use *singular* for entity. see "[Naming](#naming)" for more information
- `--schema=`: Here you can provide a [schema-String](#schema)
- `--migrate`: will automatically call `php artisan migrate` after creating the migration file
- `--ide=`: will open all files in your prefered [IDE](#open-files-in-ide)
- `--git`: will add all files to [git](#add-files-to-git)

If you want to add Services, Naming classes, Field Types, or IDE Opener you have to publish the config-file:

```
php artisan vendor:publish --provider="Webfactor\Laravel\Generators\GeneratorsServiceProvider"
```

Services
--------

[](#services)

All Services defined in the config file have to implement `Webfactor\Laravel\Generators\Contracts\ServiceInterface` and will then be called in the given order.

### Included Services

[](#included-services)

Can be removed or extended by publishing config file:

- `MigrationService`
- `FactoryService`
- `SeederService`
- Backpack CRUD:
    - `BackpackCrudModelService` (incl. `$fillable`)
    - `BackpackCrudRequestService` (incl. `rules()`)
    - `BackpackCrudControllerService` (incl. CrudColumns and CrudFields, more coming soon)
    - `SidebarService`
- `LanguageFileService`
- `RouteFileService`

### Always available (activated by option):

[](#always-available-activated-by-option)

- `OpenIdeService`
- `AddToGitService`

Schema
------

[](#schema)

The intention of this package concerning Laravel Backpack CRUD is to provide an easy way to define standard Field Types with some default options and override them if necessary.

Example:

```
php artisan make:entity blog --schema="title:string,text:summernote"
```

This will use the `StringType` and `SummernoteType` classes to create (besides all other files):

- Blog.php with `$fillable = ['title', 'text']`
- BlogRequest.php with predefined rules for each field
- BlogCrudController.php with columns and fields for `title` and `text`

If you want to add/overwrite certain options you can use something like this:

```
php artisan make:entity blog --schema="title:string(unique|default:title);rule(required|min:3|max:64),text:summernote;field(label:Content);column(label:Content)"
```

Field Types
-----------

[](#field-types)

Currently available Field Types (more coming soon):

- Date
- Number
- String
- Summernote (as a proof of concept)
- Text

The available definitions in the Field Type classes currently are:

```
public $validationRule; // 'required|min:5'...

public $migrationField = [
    'type' => 'string', // any type available for a migration file
    // optional:
    // 'unique' => true
    // 'default' => 'value'
    // 'nullable' => true
    // etc.
];

public $crudColumn = [
    'type' => 'text', // or date, number, any backpack column
    // 'label' => 'Name of label'
    // ... any option
];

public $crudField = [
    'type' => 'text', // or date, number, any backpack field
    // 'label' => 'Name of label'
    // ... prefix, suffix... any option
];
```

Naming
------

[](#naming)

You can provide your own naming convention classes by registering them in the config file. This classes should extend `Webfactor\Laravel\Generators\Contracts\NamingAbstract` to provide a certain base functionality.

Example for `Webfactor\Laravel\Generators\Schemas\Naming\CrudController`:

```
