You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Call `make:entity` artisan command to run the generation command for the full stack of the entity classes:
45
26
46
-
### Examples
47
27
```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
54
29
```
55
30
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:
61
33
62
34
```bash
63
-
>php artisan make:entity [entity-name] [options]
35
+
php artisan make:entity Forum/Blog/Post
64
36
```
65
37
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
-
70
38
#### Fields definition options
71
39
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.
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.)
81
41
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.
83
-
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.
87
-
88
-
-t|--timestamp : Add timestamp field to entity.
89
-
90
-
-T|--timestamp-required : Add timestamp 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
+
```
91
45
92
-
-j|--json : Add json field to entity.
46
+
The following field types are available to use:
47
+
48
+
| Type | Modificator | Short Option | Full Option |
-a|--has-one : Set hasOne relations between you entity and existed entity.
97
-
98
-
-A|--has-many : Set hasMany relations between you entity and existed entity.
99
-
100
-
-e|--belongs-to : Set belongsTo relations between you entity and existed entity.
101
-
102
-
-E|--belongs-to-many : Set belongsToMany relations between you entity and existed entity.
103
-
104
-
#### Single class generation mode options
64
+
Command also provides an ability to set relations, which will be added to the model
105
65
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.
66
+
```bash
67
+
php artisan make:entity Post -A Comment -A Reaction
68
+
```
107
69
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.
70
+
Relation may be placed in the subfolder, in this case - set the relative namespace from the model directory:
109
71
110
-
--only-service : Set this flag if you want to create only service.
72
+
```bash
73
+
php artisan make:entity Post -A Blog/Comment -A Forum/Common/Reaction
74
+
```
111
75
112
-
--only-controller : Set this flag if you want to create only controller.
76
+
The following options are available to set relations:
113
77
114
-
--only-requests : Set this flag if you want to create only requests.
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`|
115
84
116
-
--only-migration : Set this flag if you want to create only repository. This flag is a higher priority than --only-tests.
85
+
#### Single class generation mode options
117
86
118
-
--only-factory : Set this flag if you want to create only factory.
87
+
Command allows to generate only single entity-related class
119
88
120
-
--only-tests : Set this flag if you want to create only tests.
89
+
```bash
90
+
php artisan make:entity Post --only-tests
91
+
```
121
92
122
-
--only-seeder : Set this flag if you want to create only seeder.
93
+
The following options are available:
123
94
124
-
--only-resource : Set this flag if you want to create only resource.
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`
125
105
126
106
--only-nova-resource : Set this flag if you want to create only nova resource.
127
107
@@ -133,18 +113,43 @@ Syntax:
133
113
134
114
#### Mode combination options
135
115
136
-
--only-entity : Generate stack of classes to work with entity inside the app (Migration/Model/Service/Repository)
116
+
Sometimes you need to generate the stack of classes to work with some entity only inside the application without
117
+
the ability to manipulate it using API, or you need to create only API for already existed entity.
118
+
119
+
For this task, there are two mutually exclusive options:
120
+
121
+
1.`--only-entity`, generate stack of classes to work with entity only inside the app, it includes:
122
+
-`migration`
123
+
-`model`
124
+
-`service`
125
+
-`repository`
137
126
138
-
--only-api : Generate stack of classes to implement API part to work with entity (routes/Controller/Requests/Tests)
127
+
2.`--only-api`, generate stack of classes to implement API part to work with already existed entity:
128
+
-`routes`
129
+
-`controller`
130
+
-`requests`
131
+
-`tests`
139
132
140
-
#### Additional generation options
133
+
#### Methods setting options
134
+
135
+
By default, the command generate all methods from the CRUD stack which includes:
136
+
- create
137
+
- update
138
+
- delete
139
+
- search
140
+
- get by id
141
+
142
+
But what if we need to create the interface only for updating and reading the entity? Just use the `methods` option for it:
143
+
144
+
```bash
145
+
php artisan make:entity Post --methods=RU
146
+
```
141
147
142
-
--methods=[default: CRUD] : Don't work for `--only-entity` option. Will generate API classes (routes, controller's
143
-
methods, requests, tests) only for choosed methods.
144
-
C - created
145
-
R - read (search and get by id)
146
-
U - update
147
-
D - delete
148
+
Feel free to use any combinations of actions in any order. Each action has its own character:
0 commit comments