Gerador de Cruds para o Laravel 5
Depois de muito procurar e testar pacotes para geração de crud, encontrei este, que funciona bem e ajuda muito na criação de CRUDs básicos, já com o Bootstrap, paginação e busca.
https://github.com/appzcoder/crud-generator
Passos para a instalação
composer require appzcoder/crud-generator --dev
Em app/Providers/AppServiceProvider.php:
public function register()
{
if ($this->app->environment() == 'local') {
$this->app->register('Appzcoder\CrudGenerator\CrudGeneratorServiceProvider');
}
}
composer require laravelcollective/html
Add Provider config/app.php
Collective\Html\HtmlServiceProvider::class,
Aliases
'Form' => Collective\Html\FormFacade::class,
'HTML' => Collective\Html\HtmlFacade::class,
composer dump-autoload
Publicar o pacote do vendor:
php artisan vendor:publish --provider="Appzcoder\CrudGenerator\CrudGeneratorServiceProvider"
Está instalado e pronto para usar.
Exemplos de uso:
Posts
php artisan crud:generate Posts --fields="user_id#integer; title#string; description#text;" --view-path="" --controller-namespace="" --route-group=""
Noticias
php artisan crud:generate Noticias --fields="usuario_id#integer; titulo#string; descricao#text;" --view-path="" --controller-namespace="" --route-group=""
Posts
php artisan crud:generate Posts --fields="title#string; content#text; category#select#options=technology,tips,health" --view-path=admin --controller-namespace=Admin --route-group=admin
Comments
php artisan crud:generate Comments --fields="post_id#integer; content#text;" --view-path="" --controller-namespace="" --route-group=""
Criar banco e configurar no .env
php artisan migrate
Clientes
php artisan crud:generate Clientes --fields="nome#string; email#string;" --view-path=admin --controller-namespace=Admin --route-group=admin
php artisan migrate
Funcionarios
php artisan crud:generate Funcionarios --fields="nome#string; email#string;" --view-path="admin" --controller-namespace=Funcionarios --route-group=admin
Master a rota funcionarios/funcionarios, caso contrário não encontra
php artisan migrate
Produtos
php artisan crud:generate Produtos --fields="nome#string; descricao#string; preco#float" --view-path="site" --controller-namespace=Produtos --route-group=site
Criar no raiz (fora de site ou admin)
php artisan crud:generate Pedidos --fields="produto#string; quantidade#integer;" --view-path="" --controller-namespace=Pedidos --route-group=""
Editar a migration, para limitar o tamanho dos campos e outras características como nullable()
Outros comandos (opcionais):
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
php artisan migrate
Adicionando uma rota
Route::resource('posts', 'PostsController');
Supported Field Types
These fields are supported for migration and view's form:
Form Field Types:
text
textarea
password
email
number
date
datetime
time
radio
select
file
Migration Field Types:
string
char
varchar
date
datetime
time
timestamp
text
mediumtext
longtext
json
jsonb
binary
integer
bigint
mediumint
tinyint
smallint
boolean
decimal
double
float
enum
php artisan crud:generate Posts --fields="user_id#integer; title#string; description#text;" --view-path="" --controller-namespace="" --route-group=""
$table->string('name')->unique();
$table->string('slug')->unique();
$table->text('description')->nullable();
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->string('title');
$table->text('description');
$table->timestamps();
});
Model
php artisan crud:model Post --fillable="['title', 'body']"
Migration
php artisan crud:migration posts --schema="title#string; body#text"
View
php artisan crud:view posts --fields="title#string; body#text" --view-path="directory" --route-group=admin
Comments fornecido por CComment