Skip to content

Commit 818e598

Browse files
authored
Merge pull request #201 from RonasIT/DenTray-patch-1
Revise installation and usage sections in ReadMe.md
2 parents cf0e841 + 98b8051 commit 818e598

File tree

1 file changed

+93
-88
lines changed

1 file changed

+93
-88
lines changed

ReadMe.md

Lines changed: 93 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,139 +4,144 @@
44

55
Laravel-Entity-Generator - This generator is used to create a standard class stack for a new entity.
66

7-
### Install
7+
## Installation
88

9-
We're highly recommending to install package for only dev environment
9+
Install package using `dev` mode
1010

1111
```bash
12-
composer require ronasit/laravel-entity-generator --dev
12+
composer require ronasit/laravel-entity-generator --dev
1313
```
1414

15-
If you're on Laravel 5.5 or later the package will be auto-discovered.
16-
Otherwise, you will need to manually configure it in your config/app.php.
15+
Publish package's resources.
1716

18-
```php
19-
'providers' => [
20-
// ...
21-
RonasIT\Support\EntityGeneratorServiceProvider::class,
22-
],
17+
```bash
18+
php artisan vendor:publish --provider="RonasIT\Support\EntityGeneratorServiceProvider"
2319
```
2420

25-
For dev installation provider should be registered optionally
26-
27-
```php
28-
class AppServiceProvider
29-
{
30-
public function boot(): void
31-
{
32-
// ...
33-
if (config('app.env') === 'local') {
34-
App::register(\RonasIT\Support\EntityGeneratorServiceProvider::class);
35-
}
36-
}
37-
}
38-
```
21+
## Usage
3922

40-
And publish.
23+
### Entity generation
4124

42-
```bash
43-
php artisan vendor:publish --provider="RonasIT\Support\EntityGeneratorServiceProvider"
44-
```
25+
Call `make:entity` artisan command to run the generation command for the full stack of the entity classes:
4526

46-
### Examples
4727
```bash
48-
php artisan make:entity EntityName \
49-
-S required_string_field \
50-
--integer=not_required_integer_field \
51-
--boolean-required=required_boolean_field \
52-
-j data \
53-
-e AnotherEntityName
28+
php artisan make:entity Post
5429
```
5530

56-
### Documentation
57-
58-
`make:entity` artisan command - generate stack of classes to work with the new entity in project.
59-
60-
Syntax:
31+
Entity name may contain the subfolder, in this case generated `model` and `nova resource` will be placed to
32+
the subfolder as well:
6133

6234
```bash
63-
> php artisan make:entity [entity-name] [options]
35+
php artisan make:entity Forum/Blog/Post
6436
```
6537

66-
`entity-name` - Name of the Entity, recommended to use `CamelCase` naming style e.g. `WhitelistedDomain`
67-
68-
`options` - one or more options from the lists below
69-
7038
#### Fields definition options
7139

72-
-i|--integer : Add integer field to entity.
73-
74-
-I|--integer-required : Add required integer field to entity. If you want to specify default value you have to do it manually.
75-
76-
-f|--float : Add float field to entity.
77-
78-
-F|--float-required : Add required float field to entity. If you want to specify default value you have to do it manually.
79-
80-
-s|--string : Add string field to entity. Default type is VARCHAR(255) but you can change it manually in migration.
81-
82-
-S|--string-required : Add required string field to entity. If you want to specify default value ir size you have to do it manually.
40+
The `make:entity` provides an ability to set the entity's fields, which will be used in all created classes (e.g. Model, Create/Update requests, Test fixtures, etc.)
8341

84-
-b|--boolean : Add boolean field to entity.
85-
86-
-B|--boolean-required : Add boolean field to entity. If you want to specify default value you have to do it manually.
42+
```bash
43+
php artisan make:entity Post -S title -S text -t published_at
44+
```
8745

88-
-t|--timestamp : Add timestamp field to entity.
46+
The following field types are available to use:
47+
48+
| Type | Modificator | Short Option | Full Option |
49+
| -------- | -------- | ------- | ------- |
50+
| `integer` | | `-i` | `--integer` |
51+
| `integer` | required | `-I` | `--integer-required` |
52+
| `float` | | `-f` | `--float` |
53+
| `float` | required | `-F` | `--float-required` |
54+
| `string` | | `-s` | `--string` |
55+
| `string` | required | `-S` | `--string-required` |
56+
| `boolean` | | `-b` | `--boolean` |
57+
| `boolean` | required | `-B` | `--boolean-required` |
58+
| `datetime` | | `-t` | `--timestamp` |
59+
| `datetime` | required | `-T` | `--timestamp-required` |
60+
| `json` | | `-j` | `--json` |
8961

90-
-T|--timestamp-required : Add timestamp field to entity. If you want to specify default value you have to do it manually.
62+
#### Relations definitions options
9163

92-
-j|--json : Add json field to entity.
64+
Command also provides an ability to set relations, which will be added to the model
9365

94-
#### Relations definitions options
66+
```bash
67+
php artisan make:entity Post -A Comment -A Reaction
68+
```
9569

96-
-a|--has-one : Set hasOne relations between you entity and existed entity.
70+
Relation may be placed in the subfolder, in this case - set the relative namespace from the model directory:
9771

98-
-A|--has-many : Set hasMany relations between you entity and existed entity.
72+
```bash
73+
php artisan make:entity Post -A Blog/Comment -A Forum/Common/Reaction
74+
```
9975

100-
-e|--belongs-to : Set belongsTo relations between you entity and existed entity.
76+
The following options are available to set relations:
10177

102-
-E|--belongs-to-many : Set belongsToMany relations between you entity and existed entity.
78+
| Type | Short Option | Full Option |
79+
| -------- | ------- | ------- |
80+
| Has one | `-a` | `--has-one` |
81+
| Has many | `-A` | `--has-many` |
82+
| Belongs to | `-e` | `--belongs-to` |
83+
| Belongs to many | `-E` | `--belongs-to-many` |
10384

10485
#### Single class generation mode options
10586

106-
--only-model : Set this flag if you want to create only model. This flag is a higher priority than --only-migration, --only-tests and --only-repository.
107-
108-
--only-repository : Set this flag if you want to create only repository. This flag is a higher priority than --only-tests and --only-migration.
87+
Command allows to generate only single entity-related class
10988

110-
--only-service : Set this flag if you want to create only service.
89+
```bash
90+
php artisan make:entity Post --only-tests
91+
```
11192

112-
--only-controller : Set this flag if you want to create only controller.
93+
The following options are available:
11394

114-
--only-requests : Set this flag if you want to create only requests.
95+
- `--only-model`
96+
- `--only-repository`
97+
- `--only-service`
98+
- `--only-controller`
99+
- `--only-requests`
100+
- `--only-migration`
101+
- `--only-factory`
102+
- `--only-tests`
103+
- `--only-seeder`
104+
- `--only-resource`
115105

116-
--only-migration : Set this flag if you want to create only repository. This flag is a higher priority than --only-tests.
106+
#### Mode combination options
117107

118-
--only-factory : Set this flag if you want to create only factory.
108+
Sometimes you need to generate the stack of classes to work with some entity only inside the application without
109+
the ability to manipulate it using API, or you need to create only API for already existed entity.
119110

120-
--only-tests : Set this flag if you want to create only tests.
111+
For this task, there are two mutually exclusive options:
121112

122-
--only-seeder : Set this flag if you want to create only seeder.
113+
1. `--only-entity`, generate stack of classes to work with entity only inside the app, it includes:
114+
- `migration`
115+
- `model`
116+
- `service`
117+
- `repository`
123118

124-
--only-resource : Set this flag if you want to create only resource.
119+
2. `--only-api`, generate stack of classes to implement API part to work with already existed entity:
120+
- `routes`
121+
- `controller`
122+
- `requests`
123+
- `tests`
125124

126-
#### Mode combination options
125+
#### Methods setting options
127126

128-
--only-entity : Generate stack of classes to work with entity inside the app (Migration/Model/Service/Repository)
127+
By default, the command generate all methods from the CRUD stack which includes:
128+
- create
129+
- update
130+
- delete
131+
- search
132+
- get by id
129133

130-
--only-api : Generate stack of classes to implement API part to work with entity (routes/Controller/Requests/Tests)
134+
But what if we need to create the interface only for updating and reading the entity? Just use the `methods` option for it:
131135

132-
#### Additional generation options
136+
```bash
137+
php artisan make:entity Post --methods=RU
138+
```
133139

134-
--methods=[default: CRUD] : Don't work for `--only-entity` option. Will generate API classes (routes, controller's
135-
methods, requests, tests) only for choosed methods.
136-
C - created
137-
R - read (search and get by id)
138-
U - update
139-
D - delete
140+
Feel free to use any combinations of actions in any order. Each action has its own character:
141+
- `C` create
142+
- `U` update
143+
- `D` delete
144+
- `R` read (search and get by id)
140145

141146
## Release notes
142147

0 commit comments

Comments
 (0)