Building a laravel project comes from an idea. So why not to build the main idea behavior and leave the rest to Laragenerator in order to bootstrap your project. This package helps you to focus more about your project idea. DRY.
The current features are :
- Create Namespaces.
- Create Controllers.
- Create Form Requests.
- Create Models.
- Create Models Relationships.
- Create Migrations.
- Routes Files.
- Views files and folder.
If you have any suggestions please let me know : https://github.com/AbdelilahLbardi/Laragenerator/pulls.
First, pull in the package through Composer.
"require": {
"laracasts/generators": "master@dev",
"abdelilahlbardi/laragenerator": "^1.5"
}
And then run :
composer update
After that, include the service provider within config/app.php
.
'providers' => [
AbdelilahLbardi\LaraGenerator\Providers\LaraGeneratorServiceProvider::class,
];
The package extends Laravel Artisan and add generate:resources
command :
Here's a quick example of how to bootstrap your laravel idea:
php artisan generate:resource Backend/Article "titles:string, content:text"
Name | Type | Exemple | Usage |
Model | Argument | Backend/Article | Required |
Schema | Argument | --schema="title:string, content:text, slug:string:unique" | optional |
Relationships | Option | --relations="hasmany:tags, belongsto:user" | optional |
Without controller | Option | --without-controller | optional |
Without model | Option | --without-model | optional |
Without request | Option | --without-request | optional |
Without views | Option | --without-views | optional |
Without routes | Option | --without-routes | optional |
Without migration | Option | --without-migration | optional |
Use flash | Option | --with-flash | optional |
Rollback | Option | --rollback | optional |
- Bootstrapping with all the resources
- Bootstrapping without the model
- Bootstrapping with empty migration
- Delete the created files
php artisan generate:resource Article "title:string, content:text, slug:string:unique, user_id:integer:foreign"
You will notice additional files and folders appear in your project :
Controllers/AriclesController.php
: Here your generated controller inside the namespace that your specified.app/Models/Aritlce
: New Models folder the your Models.resources/views/articles/index.blade.php
: index view which is empty.resources/views/articles/create.blade.php
: empty create view.resources/views/articles/edit.blade.php
: empty edit view.routes/web/articles.php
: Ready routes generated.database/migrations/yyyy-mm-dd-create_articles_table.php
: Here your migration.
php artisan generate:resource Backed/Item "title:string, price:float, slug:string:unique, category_id:integer:foreign" --without-model
This will generate the same files as the recent command but will no include :
Controllers/Backend/AriclesController.php
: Here your generated controller inside the namespace that your specified.resources/views/backend/articles/index.blade.php
: index view which is empty.resources/views/backend/articles/create.blade.php
: empty create view.resources/views/backend/articles/edit.blade.php
: empty edit view.routes/web/backend/articles.php
: Ready routes generated.database/migrations/yyyy-mm-dd-create_articles_table.php
: Here your migration.
Since --schema
is an optional option, if you don't specify the --schema
option, Laragenerator generate an empty model with a simple id and timestamps.
To do so, here's a simple command.
php artisan generate:resource Backed/Item
The migration file looks like:
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('items', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('items');
}
}
php artisan generate:resource Frontend/User --rollback
With the Laragenerator `--rollback` option you don't need to delete the generated folders manually. It does all the job for you.
Notice that if you have more controllers this options doesn't delete all the controllers in the namespace.
You may want to customize the templates like the following artisan command:
php artisan vendor:publish --tag=templates
This will add to your app a new folder called Tempaltes
where you will find the following files:
Templates/Controller/Controller.txt
: Controllers Template.Templates/Model/Model.txt
: Models Template.Templates/View/index.txt
: Index View Template.Templates/View/headerCell.txt
: HTML table element header row Template.Templates/View/contentCell.txt
: HTML table element content rows Template.Templates/View/create.txt
: Create View Template.Templates/View/createInput.txt
: Create form inputs View Template.Templates/View/edit.txt
: Edit View Template.Templates/View/editInput.txt
: Edit form inputs View Template.Templates/routes.txt
: Routes File Tempalte.
Since Laragenerator uses https://github.com/laracasts/Laravel-5-Generators-Extended to generate migration and schema
you can find the its documentation here: https://github.com/laracasts/Laravel-5-Generators-Extended to know more about what to fill in `--schema` option.