Laragenerator
Laravel 5.4 generator
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., (*1)
The current features help you to :, (*2)
- Create Namespaces.
- Create Controllers.
- Create Form Requests.
- Create Models.
- Create Models Relationships.
- Create Migrations.
- Create Routes Files.
- Create Views files.
If you have any suggestions please let me know : https://github.com/AbdelilahLbardi/Laragenerator/pulls., (*3)
Installation
First, pull in the package through Composer., (*4)
"require": {
"laracasts/generators": "master@dev",
"abdelilahlbardi/laragenerator": "^1.5"
}
And then run :, (*5)
composer update
After that, include the service provider within config/app.php
., (*6)
'providers' => [
AbdelilahLbardi\LaraGenerator\Providers\LaraGeneratorServiceProvider::class,
];
Usage
The package extends Laravel Artisan and add generate:resource
command :, (*7)
Here's a quick example of how to bootstrap your laravel idea:, (*8)
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 |
Examples
Bootstrapping with all the resources
```bash
php artisan generate:resource Article "title:string, content:text, slug:string:unique, user_id:integer:foreign", (*9)
You will notice additional files and folders appearing in your project :
- `Controllers/ArticlesController.php` : Here your generated controller inside the namespace that you specified.
- `app/Models/Article` : 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.
### Bootstrapping without the model
```bash
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 :, (*10)
Since --schema
is an optional option, if you don't specify the --schema
option, Laragenerator generates an empty model with a simple id and timestamps., (*12)
To do so, here's a simple command.
```bash
php artisan generate:resource Backed/Item, (*13)
The migration file will look like:
````php
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');
}
}
````
### Rollback
```bash
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., (*14)
Notice that if you have more controllers this options doesn't delete all the controllers in the namespace., (*15)
Templates publishing
You may want to customize the templates like the following artisan command:, (*16)
php artisan vendor:publish --tag=templates
This will add a new folder to your app called Tempaltes
where you will find the following files:, (*17)
-
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.
Schema
Since Laragenerator uses https://github.com/laracasts/Laravel-5-Generators-Extended to generate migration and schema, (*18)
you can find the related documentation here: https://github.com/laracasts/Laravel-5-Generators-Extended. , (*19)