alextigaer/rep-o-matic

Create Laravel repositories easily!

Downloads

90

Stars

0

Version

1.3.2

Rep-O-Matic


Create Laravel repositories easily!

Table of Contents

Installation

composer require alextigaer/rep-o-matic

Basic usage

To create a new repository, just run the command:

php artisan repo:create RepoName

This will create:

  • 4 exceptions for the repository: 'RepoNameNotFoundException', 'RepoNameNotCreatedException', 'RepoNameNotUpdatedException' and 'RepoNameNotDeletedException'
  • The model file 'RepoName.php' inside the 'Models' directory
  • The 'Repositories' directory with 2 directories inside: 'Contracts' and 'RepoName'. The 'Contracts' directory will contain all the repositories' contracts. The 'RepoName' directory will contain all the repositories for 'RepoName'. The command will also bind the contract to the repository's file
  • The migration 'create_reponames_table'
  • The 'RepoNamesSeeder'. The command will also update the 'DatabaseSeeder' file, adding the line to call 'RepoNamesSeeder'

Options

If you want, you can use these options to customize the creation:

--e (default=y)

This option allows to choose if the exceptions should be created. The default value is set to 'y'. Other values are not considered

Description:

{--e=y : Choose whether to create the exceptions, or not [y/n]}

Usage:

// Create the repo files excluding the exceptions
php artisan repo:create RepoName --e=n

--m (default=y)

This option allows to choose if the model should be created. The default value is set to 'y'. Other values are not considered

Description:

{--m=y : Choose whether to create the model, or not [y/n]}

Usage:

// Create the repo files excluding the model
php artisan repo:create RepoName --m=n

--m-fillable

The option '--m-fillable' allows to add mass-assignable attributes to the model (and to the migration and the seeder too)

Description:

{--m-fillable=* : The mass-assignable attributes of the model}

Usage:

// Create the repo files and set 2 model mass-assignable attributes: name and email
php artisan repo:create RepoName --m-fillable=name --m-fillable=email

--m-hidden

The option '--m-hidden' allows to add hidden attributes to the model (and to the migration and the seeder too)

Description:

{--m-hidden=* : The hidden attributes of the model}

Usage:

// Create the repo files and set 2 model hidden attributes: password and pin
php artisan repo:create RepoName --m-hidden=password --m-hidden=pin

--r (default=y)

This option allows to choose if the repository should be created. The default value is set to 'y'. Other values are not considered

Description:

{--r=y : Choose whether to create the repository, or not [y/n]}

Usage:

// Create the repo files excluding the 'Repositories' folder and its content
php artisan repo:create RepoName --m=n

--n (default=y)

This option allows to choose if the migration should be created. The default value is set to 'y'. Other values are not considered

Description:

{--n=y : Choose whether to create the migration, or not [y/n]}

Usage:

// Create the repo files excluding the migration
php artisan repo:create RepoName --n=n

--n-types

The option '--n-types' allows to add the types to the migration columns. If not specified, the command will assign the type 'string' to all of the columns (if --m-fillable and/or --m-hidden are used)

Description:

{--n-types=* : The columns types of the attributes (check Laravel doc for acceptable values)}

Usage:

// Create the repo files and set: 1 mass-assignable attribute (name), 1 hidden attribute (pin) and set the types of these 2 columns as 'string' and 'integer', respectively
php artisan repo:create RepoName --m-fillable=name --m-hidden=pin --n-types=string --n-types=integer

--migrate (default=n)

This option allows to choose if the migrate command should be run. The default value is set to 'n'. Other values are not considered

Description:

{--migrate=n : Choose whether to run the command migrate, or not [y/n]}

Usage:

// Create the repo files and run the migration after its creation
php artisan repo:create RepoName --migrate=y

--s (default=y)

This option allows to choose if the seeder should be created. The default value is set to 'y'. Other values are not considered

Description:

{--s=y : Choose whether to create the seeder, or not [y/n]}

Usage:

// Create the repo files excluding the seeder
php artisan repo:create RepoName --s=n

--s-instances

The option '--s-instances' allows to add some instances to the seeder. If not specified, the command will assign the value 'VALUE' to all of the columns (if --m-fillable and/or --m-hidden are used). A default separator for the values, the character ',', is set. The syntax to add an instance is: '--s-instances="value_1,value2,...,value_n""'

Description:

{--s-instances=* : The values of the instances}

Usage:

// Create the repo files and set: 1 mass-assignable attribute (name), 1 hidden attribute (pin) and create 2 instances of 'RepoName'
php artisan repo:create RepoName --m-fillable=name --m-hidden=pin --s-instances="Alex,1234" --s-instances="Georgia,4321"

--seed (default=n)

This option allows to choose if the seed command should be run. The default value is set to 'n'. Other values are not considered

Description:

{--seed=n : Choose whether to run the command db:seed, or not [y/n]}

Usage:

// Create the repo files and run the seeding procedure
php artisan repo:create RepoName --seed=y

Usage examples

  1. Create a repo called 'ExampleOne' with 3 mass-assignable attributes, 1 hidden attribute, column types set and without creating the seeder:
php artisan repo:create ExampleOne --m-fillable=attr_1 --m-fillable=attr_2 --m-fillable=attr_2 --m-hidden=hidden_1 --n-types=string --n-types=integer --n-types=bigInteger --n-types=geometry --s=n
  1. Create a repo called 'ExampleTwo' without mass-assignable attributes, 1 hidden attribute, 2 instances and run the seeding:
php artisan repo:create ExampleTwo --m-hidden=hidden_1 --s-instances="passwordone" --s-instances="passwordtwo" --seed=y

Contributing

Feel free to suggest anything! Use pulls or contact me :)

License

Rep-O-Matic is licensed under the MIT license. Made with love, let's share it! :)

alextigaer

Author

alextigaer