PHPackages                             sawmainek/laravel-api-generator - 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. [Database &amp; ORM](/categories/database)
4. /
5. sawmainek/laravel-api-generator

ActiveLibrary[Database &amp; ORM](/categories/database)

sawmainek/laravel-api-generator
===============================

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

v1.3.3(11y ago)3152MITJavaScriptPHP &gt;=5.4.0

Since Mar 23Pushed 10y ago1 watchersCompare

[ Source](https://github.com/SawMaineK/laravel-api-generator)[ Packagist](https://packagist.org/packages/sawmainek/laravel-api-generator)[ RSS](/packages/sawmainek-laravel-api-generator/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (19)Used By (0)

Laravel API/Scaffold/CRUD Generator
===================================

[](#laravel-apiscaffoldcrud-generator)

[![Latest Stable Version](https://camo.githubusercontent.com/9a67fdd0b21d22f7fb4be7b2dd7be6dbd5d27f2497ba618e8eb872393b354b36/68747470733a2f2f706f7365722e707567782e6f72672f6d6974756c676f6c616b6979612f6c61726176656c2d6170692d67656e657261746f722f762f737461626c65)](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [![Total Downloads](https://camo.githubusercontent.com/f944659d5377501a281faceb540bbfcf7bb8de8af2e7275417b714f340b7bca1/68747470733a2f2f706f7365722e707567782e6f72672f6d6974756c676f6c616b6979612f6c61726176656c2d6170692d67656e657261746f722f646f776e6c6f616473)](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [![Monthly Downloads](https://camo.githubusercontent.com/8bc3a965a776f5d1456aac9c02c5b88d3ff5bd99c1aaa9b586d41cf44198099b/68747470733a2f2f706f7365722e707567782e6f72672f6d6974756c676f6c616b6979612f6c61726176656c2d6170692d67656e657261746f722f642f6d6f6e74686c79)](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [![Daily Downloads](https://camo.githubusercontent.com/36f42143d162bf10f94885b8359ab10405806f903a49644d851bf20e5b87bdfb/68747470733a2f2f706f7365722e707567782e6f72672f6d6974756c676f6c616b6979612f6c61726176656c2d6170692d67656e657261746f722f642f6461696c79)](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [![Latest Unstable Version](https://camo.githubusercontent.com/b42230aeaae32cc297a980c1c23b5694da8731d0d99d8d38a7945b97e866b8ee/68747470733a2f2f706f7365722e707567782e6f72672f6d6974756c676f6c616b6979612f6c61726176656c2d6170692d67656e657261746f722f762f756e737461626c65)](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [![License](https://camo.githubusercontent.com/6b3687fe633ba418566b41719cdc24ac195d5dc2d55649de037001b6fc8f6fd4/68747470733a2f2f706f7365722e707567782e6f72672f6d6974756c676f6c616b6979612f6c61726176656c2d6170692d67656e657261746f722f6c6963656e7365)](https://packagist.org/packages/mitulgolakiya/laravel-api-generator)

### Version Compability

[](#version-compability)

LaravelBranch5.0[1.3](https://github.com/mitulgolakiya/laravel-api-generator/tree/1.3)5.1.\*[1.4](https://github.com/mitulgolakiya/laravel-api-generator/tree/1.4)5.2.\*[master](https://github.com/mitulgolakiya/laravel-api-generator)I enjoy creating API's and I have worked on many projects that required them. But the problem I always faced was setting up all the boilerplate code. For example each end point needs a migration, model, controller, repository, and on and on. I wanted a way to streamline this process and that is how this package was born.

This API generator allows you to use artisan commands to automatically generate all these files saving you time. Not only does it auto generate the files but it will set the namespaces.

The artisan command can generate the following items:

- Migration File
- Model
- Repository
- Controller
- View
    - index.blade.php
    - table.blade.php
    - show.blade.php
    - show\_fields.blade.php
    - create.blade.php
    - edit.blade.php
    - fields.blade.php
- adjusts routes.php

And your simple CRUD and APIs are ready in mere seconds.

Here is the full documentation.

[Upgrade Guide](https://github.com/mitulgolakiya/laravel-api-generator/blob/master/Upgrade_Guide.md).

Documentation is in process...
==============================

[](#documentation-is-in-process)

Documentation
-------------

[](#documentation)

1. [Installation](#installation)
2. [Configuration](#configuration)
3. [Publish &amp; Initialization](#publish--initialization)
4. [Generator](#generator)
5. [Supported Field Types](#supported-field-types)
6. [Customization](#customization)
    1. [Base Controller](#base-controller)
    2. [Customize Templates](#customize-templates)
    3. [Dingo API Integration](#dingo-api-integration)
7. [Options](#options)
    1. [Paginate Records](#paginate-records)
    2. [Model Soft Deletes](#model-soft-deletes)
    3. [Fields From File](#fields-from-file)
    4. [Custom Table Name](#custom-table-name)
    5. [Skip Migration](#skip-migration)
    6. [Remember Token](#remember-token)
8. [Generator from existing tables](#generator-from-existing-tables)

***NOTE***
----------

[](#note)

Make sure if install auth "make:auth"

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

[](#installation)

1. Add this package to your composer.json:

    ```
     "require": {
         "laracasts/flash": "~1.3",
         "laravelcollective/html": "5.2.*",
         "bosnadev/repositories": "dev-master",
         "sawmainek/laravel-api-generator": "dev-master"
     }

    ```
2. Run composer update

    ```
     composer update

    ```
3. Add the ServiceProviders to the providers array in `config/app.php`.
    As we are using these two packages [laravelcollective/html](https://github.com/LaravelCollective/html) &amp; [laracasts/flash](https://github.com/laracasts/flash) as a dependency.
    so we need to add those ServiceProviders as well.

    ```
     Collective\Html\HtmlServiceProvider::class,
     Laracasts\Flash\FlashServiceProvider::class,
     Mitul\Generator\GeneratorServiceProvider::class,

    ```

    Also for convenience, add these facades in alias array in `config/app.php`.

    ```
     'Form'      => Collective\Html\FormFacade::class,
     'Html'      => Collective\Html\HtmlFacade::class,
     'Flash'     => Laracasts\Flash\Flash::class

    ```

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

[](#configuration)

Publish Configuration file `generator.php`.

```
    php artisan vendor:publish --provider="Mitul\Generator\GeneratorServiceProvider"

```

Config file (`config/generator.php`) contains path for all generated files

`base_controller` - Base Controller for all Controllers

`path_migration` - Path where Migration file to be generated
`path_model` - Path where Model file to be generated
`path_repository` - Path where Repository file to be generated
`path_controller` - Path where Controller file to be generated
`path_api_controller` - Path where API Controller file to be generated
`path_views` - Path where views will be created
`path_request` - Path where request file will be created
`path_routes` - Path of routes.php (if you are using any custom routes file)
`path_api_routes` - Path of api\_routes.php (this file will contain all api routes)

`namespace_model` - Namespace of Model
`namespace_repository` - Namespace of Repository
`namespace_controller` - Namespace of Controller
`namespace_api_controller` - Namespace of API Controller
`namespace_request` - Namespace for Request

`model_extend_class` - Extend class of Models

`api_prefix` - API Prefix `api_version` - API Version

`use_dingo_api` - Integrate APIs with dingo/api package

Publish &amp; Initialization
----------------------------

[](#publish--initialization)

Mainly, we need to do three basic things to get started.

1. Publish some common views like `errors.blade.php` &amp; `paginate.blade.php`.
2. Publish `api_routes.php` which will contain all our api routes.
3. Init `routes.php` for api routes. We need to include `api_routes.php` into main `routes.php`.

    ```
     php artisan mitul.generator:publish

    ```

Generator
---------

[](#generator)

Fire artisan command to generate API, Scaffold with CRUD views or both API as well as CRUD views.

Generate API:

```
    php artisan mitul.generator:api ModelName

```

Generate CRUD Scaffold:

```
    php artisan mitul.generator:scaffold ModelName

```

Generate CRUD Scaffold with API:

```
    php artisan mitul.generator:scaffold_api ModelName

```

e.g.

```
php artisan mitul.generator:api Project
php artisan mitul.generator:api Post

php artisan mitul.generator:scaffold Project
php artisan mitul.generator:scaffold Post

php artisan mitul.generator:scaffold_api Project
php artisan mitul.generator:scaffold_api Post

```

Here is the sample [fields input json](https://github.com/mitulgolakiya/laravel-api-generator/blob/master/samples/fields.json)

Supported HTML Field Types
--------------------------

[](#supported-html-field-types)

Here is the list of supported field types with options:

- text
- textarea
- password
- email
- file
- checkbox
- radio:male,female,option3,option4
- number
- date
- select:India,USA

Customization
-------------

[](#customization)

### Base Controller

[](#base-controller)

If you want to use your own base controller or want to extend/modify default AppBaseController then you can have following options:

1. If you want to use another controller (recommended to extends AppBaseController with new controller) as base controller then modify `base_controller` value in `config/generator.php`
2. If you want to modify AppBaseController then,

    1. Publish AppBaseController in your controllers path

        php artisan mitul.generator:publish --baseController
    2. Modify the content of `AppBaseController.php` and set it as a `base_controller` in `config/generator.php`

### Customize Templates

[](#customize-templates)

To use your own custom templates,

1. Publish templates to `/resources/api-generator-templates`

    ```
     php artisan mitul.generator:publish --templates

    ```
2. Leave only those templates that you want to change. Remove the templates that do not plan to change.

Options
-------

[](#options)

### Paginate Records

[](#paginate-records)

To paginate records, you can specify paginate option, e.g.

```
    php artisan mitul.generator:api Post --paginate=10

```

### Model Soft Deletes

[](#model-soft-deletes)

To use SoftDelete, use softDelete option,

```
    php artisan mitul.generator:api Post --softDelete

```

### Fields From File

[](#fields-from-file)

If you want to pass fields from file then you can create fields json file and pass it via command line. Here is the sample [fields.json](https://github.com/mitulgolakiya/laravel-api-generator/blob/master/samples/fields.json)

You have to pass option `--fieldsFile=absolute_file_path_or_path_from_base_directory` with command. e.g.

```
     php artisan mitul.generator:scaffold_api Post --fieldsFile="/Users/Mitul/laravel-api-generator/fields.json"
     php artisan mitul.generator:scaffold_api Post --fieldsFile="fields.json"

```

### Custom Table Name

[](#custom-table-name)

You can also specify your own custom table name by,

```
    php artisan mitul.generator:api Post --tableName=custom_table_name

```

### Skip Migration

[](#skip-migration)

You can also skip migration generation,

```
    php artisan mitul.generator:api Post --skipMigration

```

### Remember Token

[](#remember-token)

To generate rememberToken field in migration file,

```
    php artisan mitul.generator:api Post --rememberToken

```

Generator from existing tables
------------------------------

[](#generator-from-existing-tables)

To use generator with existing table, you can specify `--fromTable` option. `--tableName` option is required and you need to specify table name.

Just make sure, you have installed `doctrine/dbal` package.

**Limitation:** As of now it is not fully working (work is in progress). It will not create migration file. You need to tweak some of the things in your generated files like timestamps, primary key etc.

```
    php artisan mitul.generator:api Post --fromTable --tableName=posts

```

Credits
-------

[](#credits)

This API Generator is created by [Mitul Golakiya](https://github.com/mitulgolakiya).

**Bugs &amp; Forks are welcomed :)**

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 64.7% 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 ~21 days

Recently: every ~63 days

Total

15

Last Release

3814d ago

PHP version history (2 changes)v1.0PHP &gt;=5.4.0

1.4.x-devPHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/9cc20d3898a509ca671f81ab6c703834fefeddf6214f0e38db6b022907b1d8a9?d=identicon)[SawMaineK](/maintainers/SawMaineK)

---

Top Contributors

[![mitulgolakiya](https://avatars.githubusercontent.com/u/1908535?v=4)](https://github.com/mitulgolakiya "mitulgolakiya (180 commits)")[![SawMaineK](https://avatars.githubusercontent.com/u/4074646?v=4)](https://github.com/SawMaineK "SawMaineK (45 commits)")[![KIVagant](https://avatars.githubusercontent.com/u/517501?v=4)](https://github.com/KIVagant "KIVagant (14 commits)")[![gayanhewa](https://avatars.githubusercontent.com/u/1681406?v=4)](https://github.com/gayanhewa "gayanhewa (9 commits)")[![jonphipps](https://avatars.githubusercontent.com/u/12743?v=4)](https://github.com/jonphipps "jonphipps (7 commits)")[![anand-patel](https://avatars.githubusercontent.com/u/5024250?v=4)](https://github.com/anand-patel "anand-patel (4 commits)")[![DarkaOnLine](https://avatars.githubusercontent.com/u/1171698?v=4)](https://github.com/DarkaOnLine "DarkaOnLine (4 commits)")[![alvioleegia](https://avatars.githubusercontent.com/u/3324830?v=4)](https://github.com/alvioleegia "alvioleegia (3 commits)")[![gildniy](https://avatars.githubusercontent.com/u/3137192?v=4)](https://github.com/gildniy "gildniy (3 commits)")[![jclyons52](https://avatars.githubusercontent.com/u/6395559?v=4)](https://github.com/jclyons52 "jclyons52 (3 commits)")[![preshetin](https://avatars.githubusercontent.com/u/4620130?v=4)](https://github.com/preshetin "preshetin (2 commits)")[![santiagogg](https://avatars.githubusercontent.com/u/2448234?v=4)](https://github.com/santiagogg "santiagogg (1 commits)")[![ericlbarnes](https://avatars.githubusercontent.com/u/116662?v=4)](https://github.com/ericlbarnes "ericlbarnes (1 commits)")[![thylo](https://avatars.githubusercontent.com/u/1242863?v=4)](https://github.com/thylo "thylo (1 commits)")[![wink-](https://avatars.githubusercontent.com/u/1276095?v=4)](https://github.com/wink- "wink- (1 commits)")

---

Tags

apilaravelmigrationgeneratorscaffoldmodelcrud

### Embed Badge

![Health badge](/badges/sawmainek-laravel-api-generator/health.svg)

```
[![Health](https://phpackages.com/badges/sawmainek-laravel-api-generator/health.svg)](https://phpackages.com/packages/sawmainek-laravel-api-generator)
```

PHPackages © 2026

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