13 May 2019

Laravel Generator use crud-generator


Laravel Generator use crud-generator. Laravel generator makes it easy for us to create projects. Very troublesome if we make a project from the beginning. Using a generator will speed up the making of our application projects.

  1. laravel
  2. pacakge https://github.com/appzcoder/crud-generator

Requirements

Laravel >= 5.3
PHP >= 5.6.4

Installation

composer require appzcoder/crud-generator --dev
To get started, you should add the appzcoder/crud-generator Composer dependency to your project:
composer require appzcoder/crud-generator --dev
Once the package is installed, you should register the Appzcoder\CrudGenerator\CrudGeneratorServiceProvider service provider. Normally, Laravel 5.5+ will register the service provider automatically.
After that, publish its assets using the vendor:publish Artisan command:
php artisan vendor:publish --provider="Appzcoder\CrudGenerator\CrudGeneratorServiceProvider"
Laravel older 5.5
If you're using an older verson of Laravel (<5 .5="" add="" app="" file.="" font="" just="" manually="" ppserviceprovider.php="" provider="" roviders="" the="" then="" to="">
public function register(){    if ($this->app->environment() == 'local') {        $this->app->register('Appzcoder\CrudGenerator\CrudGeneratorServiceProvider');    }}
And since, we're using laravelcollective/html as dependency you should add its service provider in the config/app.php file. Check the docs for details.
'providers' => [    //...
    Collective\Html\HtmlServiceProvider::class,],
'aliases' => [    //...
    'Form' => Collective\Html\FormFacade::class,    'HTML' => Collective\Html\HtmlFacade::class,],

Usage

php artisan crud:generate Posts --fields='title#string; content#text; category#select#options={"technology": "Technology", "tips": "Tips", "health": "Health"}' --view-path=admin --controller-namespace=Admin --route-group=admin --form-helper=html

Other Commands

For controller:
php artisan crud:controller PostsController --crud-name=posts --model-name=Post --view-path="directory" --route-group=admin
For model:
php artisan crud:model Post --fillable="['title', 'body']"
For migration:
php artisan crud:migration posts --schema="title#string; body#text"
For view:
php artisan crud:view posts --fields="title#string; body#text" --view-path="directory" --route-group=admin --form-helper=html
By default, the generator will attempt to append the crud route to your Route file. If you don't want the route added, you can use this option --route=no.

After creating all resources, run migrate command. If necessary, include the route for your crud as well.

php artisan migrate
The following image is a generated example from the appzcoder package. Very useful in working on our application project.

So, if there is a package to speed up the creation of our application, why don't we use an existing package? or do you want to make your own package? please try, in the next post we will discuss about making a package in Laravel. get it touch guys

No comments: