Skip to content

Commit

Permalink
laravel generator change
Browse files Browse the repository at this point in the history
  • Loading branch information
foryoufeng committed Jan 19, 2019
1 parent f0fda8e commit 5cb44b1
Show file tree
Hide file tree
Showing 58 changed files with 5,750 additions and 1,314 deletions.
10 changes: 8 additions & 2 deletions changelog.md
Expand Up @@ -2,7 +2,13 @@

All notable changes to `laravel-generator` will be documented in this file.

## Version 1.0
* # Version 2.0
* add tables / 添加数据表
* add templates and can edit/add / 增加模板,可以进行添加和编辑
* add Foreign and Relationships / 增加外键和关联关系
* add some fields such as display name and rule and so on /新增显示名称、规则等字段
---
* #Version 1.0

### Added
- Everything
- Everything / 第一个版本
9 changes: 3 additions & 6 deletions composer.json
Expand Up @@ -10,9 +10,9 @@
}
],
"homepage": "https://github.com/foryoufeng/laravel-generator",
"keywords": ["Laravel", "laravel-generator"],
"keywords": ["Laravel", "laravel-generator","code generator"],
"require": {
"laravel/framework": "^5.5",
"laravel/framework": "^5.0",
"barryvdh/laravel-ide-helper": "^2.4",
"doctrine/dbal": "^2.7",
"prettus/l5-repository": "^2.6"
Expand All @@ -34,10 +34,7 @@
"laravel": {
"providers": [
"Foryoufeng\\Generator\\GeneratorServiceProvider"
],
"aliases": {
"Generator": "Foryoufeng\\Generator\\Facades\\Generator"
}
]
}
}
}
46 changes: 15 additions & 31 deletions config/generator.php
Expand Up @@ -4,36 +4,20 @@
'name' => 'Laravel-generator',
//the url to access
'route'=>'generator',
'modelPath'=>'App\\Models\\',
'views'=>[],
'multiple'=>[
// group file
[
'name'=>'controllers',
//The file suffix
'postfix'=>'Controller',
'group'=>[
[
'namespace'=>'App\\Http\\Controllers\\',
'stub'=>resource_path('generators').'/controllers/home_controller.stub',
'isChecked'=>true //you can change it to false
],
[
'namespace'=>'App\\Http\\Controllers\\Api\\',
'stub'=>resource_path('generators').'/controllers/api_controller.stub',
'isChecked'=>true
]
],
]
],
//one file
'single'=>[
[
'name'=>'dao',
'namespace'=>'App\\Http\\Daos\\',
'stub'=>resource_path('generators').'/dao.stub',
'isChecked'=>true,
'postfix'=>'Dao'
]
//the rule can be used by the field
'rules'=>[
'string',
'email',
'file',
'numeric',
'array',
'alpha',
'alpha_dash',
'alpha_num',
'date',
'boolean',
'distinct',
'phone',
'custom'
],
];
98 changes: 40 additions & 58 deletions readme.md
Expand Up @@ -7,10 +7,12 @@
Requirements
------------
- PHP >= 7.0.0
- Laravel >= 5.5.0
- Laravel >= 5

# For GUI
<img src="https://cdn.linkgoup.com/laravel-generator.png" alt="laravel-admin">
<img src="https://cdn.linkgoup.com/laravel_generator_v2_en_index.png" alt="laravel-generator">

## [More Docs](https://doc.linkgoup.com/docs/show/669)

## Installation

Expand All @@ -20,14 +22,24 @@ Via Composer
composer require --dev foryoufeng/laravel-generator
```

Then run the command to publish resources and config:
If you do not run Laravel 5.5 (or higher), then add the service provider in `config/app.php`:
```
Foryoufeng\Generator\GeneratorServiceProvider::class
```

Then run the command to install the generator
```
php artisan vendor:publish --provider="Foryoufeng\Generator\GeneratorServiceProvider"
php artisan generator:install
```
After run command you can find config file in `config/generator.php`,and you can configure the position of the stub and the file you want to generate, the default stub will be in `resources/generators` directory, in this file you can config your file.
now you can access your application `http://yourhost/generator` to use the `laravel-generator`

After run command you can find config file in `config/generator.php`,and now you can access your application `http://yourhost/generator` to use the `laravel-generator`

After the installation is complete, the project generates templates such as model, controllers and views by default. Other templates can be added or modified according to the actual needs of the project.

## templates

<img src="https://cdn.linkgoup.com/laravel_generator_en_template.png" alt="laravel-generator">

## Usage
the `generator.php` doc
```
Expand All @@ -37,63 +49,33 @@ return [
'name' => 'Laravel-generator',
//the url to access
'route'=>'generator',//you can change the access url if you do not like it
'modelPath'=>'App\\Models\\', //where your models in
'views'=>[], //waiting to finish
'multiple'=>[ // to genetate multiple file
// group file
[
'name'=>'controllers', // which is the label name in the html
//The file suffix
'postfix'=>'Controller', //such as UserController,the postfix is Controller ,or UserTest the postfix is Test
'group'=>[
[
'namespace'=>'App\\Http\\Controllers\\',
'stub'=>resource_path('generators').'/controllers/home_controller.stub', //where the stub in
'isChecked'=>true //you can change it to false
],
[
'namespace'=>'App\\Http\\Controllers\\Api\\',
'stub'=>resource_path('generators').'/controllers/api_controller.stub',
'isChecked'=>true
]
],
]
],
//one file
'single'=>[ // to genetate one file
[
'name'=>'dao',
'namespace'=>'App\\Http\\Daos\\',
'stub'=>resource_path('generators').'/dao.stub',
'isChecked'=>true,
'postfix'=>'Dao'
]
],
//the rule can be used by the field , You can define the format of the fields you need.
'rules'=>[
'string',
'email',
'file',
'numeric',
'array',
'alpha',
'alpha_dash',
'alpha_num',
'date',
'boolean',
'distinct',
'phone',
],
];
```

## stub
```
<?php
You can define the format of the stub you need followed by my rules,such as

<img src="https://cdn.linkgoup.com/laravel_generator_v2_en.png" alt="laravel-generator">

## Notice

Only Chinese and English are supported by laravel generator now

namespace DummyNamespace; //which is the `namespace` you defined in the config
use DummyModelNamespace; //is the model such as App\Models\User
use Prettus\Repository\Eloquent\BaseRepository;
//is the `model_name`.`postfix` such as `UserController`
class DummyClass extends BaseRepository
{
/**
* @return string
*/
public function model()
{
//`DummyModelUcfirst` is mean to the model_name ,such as `User`
return DummyModelUcfirst::class;
}
}
```
## Change log

Please see the [changelog](changelog.md) for more information on what has changed recently.
Expand Down
100 changes: 44 additions & 56 deletions readme_zh_CN.md
Expand Up @@ -5,10 +5,12 @@
要求
------------
- PHP >= 7.0.0
- Laravel >= 5.5.0
- Laravel >= 5

# UI界面
<img src="https://cdn.linkgoup.com/laravel-generator.png" alt="laravel-admin">
<img src="https://cdn.linkgoup.com/laravel_generator_zh_index.png" alt="laravel-generator">

## [更多文档](https://doc.linkgoup.com/docs/show/669)

## 安装

Expand All @@ -18,14 +20,28 @@
composer require --dev foryoufeng/laravel-generator
```

运行如下命令来发布资源文件
如果你是运行的Laravel 5.5以下的版本,需要在`config/app.php`的service provider中添加:

```
Foryoufeng\Generator\GeneratorServiceProvider::class
```

运行如下命令来安装代码生成器

```
php artisan vendor:publish --provider="Foryoufeng\Generator\GeneratorServiceProvider"
php artisan generator:install
```
运行后,你能在`config/generator.php`中配置你的代码生成数据,代码模板默认在`resources/generators` 目录下,

运行后,你能在`config/generator.php`中配置你的代码

现在你可以访问你的应用url`http://yourhost/generator` 来使用`laravel-generator`

安装完成后,项目默认生成了model,controllers和views这几个模板,其他模板可以根据自己项目的实际需要进行添加或者修改

## 模板

<img src="https://cdn.linkgoup.com/laravel_generator_zh_template.png" alt="laravel-generator">

## 用法
`generator.php` 文件说明
```
Expand All @@ -35,62 +51,34 @@ return [
'name' => 'Laravel-generator',//应用的名称
//访问的地址
'route'=>'generator',//如果你不想访问这个地址,可以换掉
'modelPath'=>'App\\Models\\', //模型所在的命名空间
'views'=>[], //待实现
'multiple'=>[ // 多文件生成
// group file
[
'name'=>'controllers', // 在界面的label中显示的名称
//文件的后缀
'postfix'=>'Controller', //如UserController,后缀是Controller ,或者 UserTest 后缀是Test
'group'=>[
[
'namespace'=>'App\\Http\\Controllers\\',//所在的空间
'stub'=>resource_path('generators').'/controllers/home_controller.stub', //模板所在位置
'isChecked'=>true //页面上是否选中
],
[
'namespace'=>'App\\Http\\Controllers\\Api\\',
'stub'=>resource_path('generators').'/controllers/api_controller.stub',
'isChecked'=>true
]
],
]
],
'single'=>[ // 单个文件生成
[
'name'=>'dao',
'namespace'=>'App\\Http\\Daos\\',
'stub'=>resource_path('generators').'/dao.stub',
'isChecked'=>true,
'postfix'=>'Dao'
]
],
//字段的规则 , 你也可以定义你自己的验证规则
'rules'=>[
'string',
'email',
'file',
'numeric',
'array',
'alpha',
'alpha_dash',
'alpha_num',
'date',
'boolean',
'distinct',
'phone',
],
];
```

## 模板
```
<?php
你可以根据项目给出的模板格式来定义你说需要的模板,例如

<img src="https://cdn.linkgoup.com/laravel_generator_v2_zh.png" alt="laravel-generator">


## 注意

项目现在只支持中文和英文2种语言

namespace DummyNamespace; //会被替换为你在配置文件中定义的`namespace`
use DummyModelNamespace; //模型的路径 如App\Models\User
use Prettus\Repository\Eloquent\BaseRepository;
//变成模型名拼接后缀`model_name`.`postfix` 如`UserController`
class DummyClass extends BaseRepository
{
/**
* @return string
*/
public function model()
{
//`DummyModelUcfirst` 对应模型名,如 `User`
return DummyModelUcfirst::class;
}
}
```
## 更新记录

查看 [changelog](changelog.md) 获取更新记录
Expand Down

0 comments on commit 5cb44b1

Please sign in to comment.