alextigaer/rep-o-matic

轻松创建 Laravel 仓库!

1.3.2 2018-05-19 17:24 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:43:09 UTC


README

轻松创建 Laravel 仓库!

目录

安装

composer require alextigaer/rep-o-matic

基本用法

要创建一个新的仓库,只需运行以下命令

php artisan repo:create RepoName

这将创建

  • 4 个异常:'RepoNameNotFoundException'、'RepoNameNotCreatedException'、'RepoNameNotUpdatedException' 和 'RepoNameNotDeletedException'
  • 位于 'Models' 目录中的模型文件 'RepoName.php'
  • 包含 2 个子目录 'Contracts' 和 'RepoName' 的 'Repositories' 目录。'Contracts' 目录将包含所有仓库的接口。'RepoName' 目录将包含所有名为 'RepoName' 的仓库。该命令还将绑定接口到仓库文件
  • 迁移 'create_reponames_table'
  • 'RepoNamesSeeder'。该命令还将更新 'DatabaseSeeder' 文件,添加调用 'RepoNamesSeeder' 的行

选项

如果您想,您可以使用这些选项来自定义创建过程

--e (默认=y)

此选项允许选择是否创建异常。默认值设置为 'y'。其他值不考虑

描述

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

用法

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

--m (默认=y)

此选项允许选择是否创建模型。默认值设置为 'y'。其他值不考虑

描述

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

用法

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

--m-fillable

'--m-fillable' 选项允许向模型(以及迁移和种子文件)添加可批量分配的属性

描述

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

用法

// 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

'--m-hidden' 选项允许向模型(以及迁移和种子文件)添加隐藏属性

描述

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

用法

// 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 (默认=y)

此选项允许选择是否创建仓库。默认值设置为 'y'。其他值不考虑

描述

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

用法

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

--n (默认=y)

此选项允许选择是否创建迁移。默认值设置为 'y'。其他值不考虑

描述

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

用法

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

--n-types

'--n-types' 选项允许向迁移列添加类型。如果没有指定,命令将把类型 'string' 分配给所有列(如果使用了 --m-fillable 和/或 --m-hidden)

描述

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

用法

// 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 (默认=n)

此选项允许选择是否运行迁移命令。默认值设置为 'n'。其他值不考虑

描述

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

用法

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

--s (默认=y)

此选项允许选择是否创建种子。默认值设置为 'y'。其他值不考虑

描述

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

用法

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

--s-instances

选项'--s-instances'允许向seeder添加一些实例。如果未指定,则命令将为所有列分配值'VALUE'(如果使用'--m-fillable'和/或'--m-hidden')。默认分隔符为逗号','。添加实例的语法为:'--s-instances="value_1,value2,...,value_n""'

描述

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

用法

// 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 (默认=n)

此选项允许选择是否运行种子命令。默认值设置为'n'。其他值不予考虑

描述

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

用法

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

用法示例

  1. 创建一个名为'ExampleOne'的仓库,具有3个可批量分配属性,1个隐藏属性,设置列类型,但不创建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. 创建一个名为'ExampleTwo'的仓库,没有可批量分配属性,1个隐藏属性,2个实例,并运行种子操作
php artisan repo:create ExampleTwo --m-hidden=hidden_1 --s-instances="passwordone" --s-instances="passwordtwo" --seed=y

贡献

请随时提出建议!使用pull请求或联系我:)

许可协议

Rep-O-Matic遵循MIT许可协议。用爱制作,让我们一起分享!:)