Generate Model, attribute, relation, scope trait and repository for Laravel 5 Boilerplate via console command
composer require --dev hariadi/laravel-boilerplate-generatorPackage already support auto discover and ready to use.
Register service provider by adding to your config/app.php:
Hariadi\Boilerplate\GeneratorCommandServiceProvider::class,If you want this lib only for dev, you can add the following code to your app/Providers/AppServiceProvider.php file, within the register() method:
public function register()
{
if ($this->app->environment() !== 'production') {
$this->app->register(\Hariadi\Boilerplate\GeneratorCommandServiceProvider::class);
}
// ...
}Show command list:
php artisan listYou will see:
app
app:attribute Create a new attribute traits for model
app:method Create a new method traits for model
app:model Create a new Eloquent model class with attribute, relationship and scope traits
app:relationship Create a new relationship traits for model
app:repository Create a new repository class
app:scope Create a new scope traits for modelOptions
-N|--namespace: The namespace class. Output strategy will follow this namespace
php artisan app:model ModelNameGenerate ModelName.php under Models directory, and traits for ModelNameAttribute, ModelNameRelationship, ModelNameScope under Models\ModelName\Traits directory.
Options
-N|--namespace: The namespace class. Output strategy will follow this namespace
php artisan app:attribute ModelNameGenerate ModelNameAttribute.php under Models/Traits/Attribute directory.
Options
-N|--namespace: The namespace class. Output strategy will follow this namespace
php artisan app:method ModelNameGenerate ModelNameMethod.php under Models/Traits/Method directory.
Options
-N|--namespace: The namespace class. Output strategy will follow this namespace
php artisan app:relation ModelNameGenerate ModelNameRelationship.php under Models/Traits/Relationship directory.
Options
-N|--namespace: The namespace class. Output strategy will follow this namespace
php artisan app:scope ModelNameGenerate ModelNameScope.php under Models/Traits/Scope directory.
Options
-d|--disable-softdelete: Disable softdelete method (forceDeleteandrestore)
php artisan app:repository Backend/ModelNameGenerate ModelNameRepository.php under app/Repositories/Event directory.
Example files and directories output:
php artisan app:model ModelName
php artisan app:model AnotherModelNameapp/Models
├── AnotherModelName
│ ├── AnotherModelName.php
│ └── Traits
│ ├── Attribute
│ │ └── AnotherModelNameAttribute.php
│ ├── Method
│ │ └── AnotherModelNameMethod.php
│ ├── Relationship
│ │ └── AnotherModelNameRelationship.php
│ └── Scope
│ └──AnotherModelNameScope.php
└── ModelName
├── ModelName.php
└── Traits
├── Attribute
│ └── ModelNameAttribute.php
├── Method
│ └── ModelNameMethod.php
├── Relationship
│ └── ModelNameRelationship.php
└── Scope
└── ModelNameScope.php
Generated combined in given namspace option. Example files and directories output:
php artisan app:model ModelName --namespace=Survey
php artisan app:model AnotherModelName --namespace=Surveyapp/Models
└── Survey
├── ModelName.php
├── AnotherModelName.php
└── Traits
├── Attribute
│ ├── ModelNameAttribute.php
│ └── AnotherModelNameAttribute.php
├── Method
│ ├── ModelNameMethod.php
│ └── AnotherModelNameMethod.php
├── Relationship
│ ├── ModelNameRelationship.php
│ └── AnotherModelNameRelationship.php
└── Scope
├── ModelNameScope.php
└── AnotherModelNameScope.php
The Laravel Boilerplate Generator command is open-sourced software licensed under the MIT license