-
Notifications
You must be signed in to change notification settings - Fork 318
/
models.php
460 lines (405 loc) · 16.7 KB
/
models.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Configurations
|--------------------------------------------------------------------------
|
| In this section you may define the default configuration for each model
| that will be generated from any database.
|
*/
'*' => [
/*
|--------------------------------------------------------------------------
| Model Files Location
|--------------------------------------------------------------------------
|
| We need a location to store your new generated files. All files will be
| placed within this directory. When you turn on base files, they will
| be placed within a Base directory inside this location.
|
*/
'path' => app_path('Models'),
/*
|--------------------------------------------------------------------------
| Model Namespace
|--------------------------------------------------------------------------
|
| Every generated model will belong to this namespace. It is suggested
| that this namespace should follow PSR-4 convention and be very
| similar to the path of your models defined above.
|
*/
'namespace' => 'App\Models',
/*
|--------------------------------------------------------------------------
| Parent Class
|--------------------------------------------------------------------------
|
| All Eloquent models should inherit from Eloquent Model class. However,
| you can define a custom Eloquent model that suits your needs.
| As an example one custom model has been added for you which
| will allow you to create custom database castings.
|
*/
'parent' => Illuminate\Database\Eloquent\Model::class,
/*
|--------------------------------------------------------------------------
| Traits
|--------------------------------------------------------------------------
|
| Sometimes you may want to append certain traits to all your models.
| If that is what you need, you may list them bellow.
| As an example we have a BitBooleans trait which will treat MySQL bit
| data type as booleans. You might probably not need it, but it is
| an example of how you can customize your models.
|
*/
'use' => [
// Reliese\Database\Eloquent\BitBooleans::class,
// Reliese\Database\Eloquent\BlamableBehavior::class,
],
/*
|--------------------------------------------------------------------------
| Model Connection
|--------------------------------------------------------------------------
|
| If you wish your models had appended the connection from which they
| were generated, you should set this value to true and your
| models will have the connection property filled.
|
*/
'connection' => false,
/*
|--------------------------------------------------------------------------
| Timestamps
|--------------------------------------------------------------------------
|
| If your tables have CREATED_AT and UPDATED_AT timestamps you may
| enable them and your models will fill their values as needed.
| You can also specify which fields should be treated as timestamps
| in case you don't follow the naming convention Eloquent uses.
| If your table doesn't have these fields, timestamps will be
| disabled for your model.
|
*/
'timestamps' => true,
// 'timestamps' => [
// 'enabled' => true,
// 'fields' => [
// 'CREATED_AT' => 'created_at',
// 'UPDATED_AT' => 'updated_at',
// ]
// ],
/*
|--------------------------------------------------------------------------
| Soft Deletes
|--------------------------------------------------------------------------
|
| If your tables support soft deletes with a DELETED_AT attribute,
| you can enable them here. You can also specify which field
| should be treated as a soft delete attribute in case you
| don't follow the naming convention Eloquent uses.
| If your table doesn't have this field, soft deletes will be
| disabled for your model.
|
*/
'soft_deletes' => true,
// 'soft_deletes' => [
// 'enabled' => true,
// 'field' => 'deleted_at',
// ],
/*
|--------------------------------------------------------------------------
| Date Format
|--------------------------------------------------------------------------
|
| Here you may define your models' date format. The following format
| is the default format Eloquent uses. You won't see it in your
| models unless you change it to a more convenient value.
|
*/
'date_format' => 'Y-m-d H:i:s',
/*
|--------------------------------------------------------------------------
| Pagination
|--------------------------------------------------------------------------
|
| Here you may define how many models Eloquent should display when
| paginating them. The default number is 15, so you might not
| see this number in your models unless you change it.
|
*/
'per_page' => 15,
/*
|--------------------------------------------------------------------------
| Base Files
|--------------------------------------------------------------------------
|
| By default, your models will be generated in your models path, but
| when you generate them again they will be replaced by new ones.
| You may want to customize your models and, at the same time, be
| able to generate them as your tables change. For that, you
| can enable base files. These files will be replaced whenever
| you generate them, but your customized files will not be touched.
|
*/
'base_files' => false,
/*
|--------------------------------------------------------------------------
| Snake Attributes
|--------------------------------------------------------------------------
|
| Eloquent treats your model attributes as snake cased attributes, but
| if you have camel-cased fields in your database you can disable
| that behaviour and use camel case attributes in your models.
|
*/
'snake_attributes' => true,
/*
|--------------------------------------------------------------------------
| Indent options
|--------------------------------------------------------------------------
|
| As default indention is done with tabs, but you can change it by setting
| this to the amount of spaces you that you want to use for indentation.
| Usually you will use 4 spaces instead of tabs.
|
*/
'indent_with_space' => 0,
/*
|--------------------------------------------------------------------------
| Qualified Table Names
|--------------------------------------------------------------------------
|
| If some of your tables have cross-database relationships (probably in
| MySQL), you can make sure your models take into account their
| respective database schema.
|
| Can Either be NULL, FALSE or TRUE
| TRUE: Schema name will be prepended on the table
| FALSE:Table name will be set without schema name.
| NULL: Table name will follow laravel pattern,
| i.e if class name(plural) matches table name, then table name will not be added
*/
'qualified_tables' => false,
/*
|--------------------------------------------------------------------------
| Hidden Attributes
|--------------------------------------------------------------------------
|
| When casting your models into arrays or json, the need to hide some
| attributes sometimes arise. If your tables have some fields you
| want to hide, you can define them bellow.
| Some fields were defined for you.
|
*/
'hidden' => [
'*secret*', '*password', '*token',
],
/*
|--------------------------------------------------------------------------
| Mass Assignment Guarded Attributes
|--------------------------------------------------------------------------
|
| You may want to protect some fields from mass assignment. You can
| define them bellow. Some fields were defined for you.
| Your fillable attributes will be those which are not in the list
| excluding your models' primary keys.
|
*/
'guarded' => [
// 'created_by', 'updated_by'
],
/*
|--------------------------------------------------------------------------
| Casts
|--------------------------------------------------------------------------
|
| You may want to specify which of your table fields should be casted as
| something different than a string. For instance, you may want a
| text field be casted as an array or and object.
|
| You may define column patterns which will be casted using the value
| assigned. We have defined some fields for you. Feel free to
| modify them to fit your needs.
|
*/
'casts' => [
'*_json' => 'json',
],
/*
|--------------------------------------------------------------------------
| Excluded Tables
|--------------------------------------------------------------------------
|
| When performing the generation of models you may want to skip some of
| them, because you don't want a model for them or any other reason.
| You can define those tables bellow. The migrations table was
| filled for you, since you may not want a model for it.
|
*/
'except' => [
'migrations',
],
/*
|--------------------------------------------------------------------------
| Specified Tables
|--------------------------------------------------------------------------
|
| You can specify specific tables. This will generate the models only
| for selected tables, ignoring the rest.
|
*/
'only' => [
// 'users',
],
/*
|--------------------------------------------------------------------------
| Table Prefix
|--------------------------------------------------------------------------
|
| If you have a prefix on your table names but don't want it in the model
| and relation names, specify it here.
|
*/
'table_prefix' => '',
/*
|--------------------------------------------------------------------------
| Lower table name before doing studly
|--------------------------------------------------------------------------
|
| If tables names are capitalised using studly produces incorrect name
| this can help fix it ie TABLE_NAME now becomes TableName
|
*/
'lower_table_name_first' => false,
/*
|--------------------------------------------------------------------------
| Relation Name Strategy
|--------------------------------------------------------------------------
|
| How the relations should be named in your models.
|
| 'related' Use the related table as the relation name.
| (post.author --> user.id)
generates Post::user() and User::posts()
|
| 'foreign_key' Use the foreign key as the relation name.
| (post.author --> user.id)
| generates Post::author() and User::posts_author()
| Column id's are ignored.
| (post.author_id --> user.id)
| generates the same as above.
| When the foreign key is redundant, it is omited.
| (post.user_id --> user.id)
| generates User::posts() and not User::posts_user()
*/
'relation_name_strategy' => 'related',
// 'relation_name_strategy' => 'foreign_key',
/*
|--------------------------------------------------------------------------
| Determines need or not to generate constants with properties names like
|
| ...
| const AGE = 'age';
| const USER_NAME = 'user_name';
| ...
|
| that later can be used in QueryBuilder like
|
| ...
| $builder->select([User::USER_NAME])->where(User::AGE, '<=', 18);
| ...
|
| that helps to avoid typos in strings when typing field names and allows to use
| code competition with available model's field names.
*/
'with_property_constants' => false,
/*
|--------------------------------------------------------------------------
| Disable Pluralization Name
|--------------------------------------------------------------------------
|
| You can disable pluralization tables and relations
|
*/
'pluralize' => true,
/*
|--------------------------------------------------------------------------
| Disable Pluralization Except For Certain Tables
|--------------------------------------------------------------------------
|
| You can enable pluralization for certain tables
|
*/
'override_pluralize_for' => [
],
],
/*
|--------------------------------------------------------------------------
| Database Specifics
|--------------------------------------------------------------------------
|
| In this section you may define the default configuration for each model
| that will be generated from a specific database. You can also nest
| table specific configurations.
| These values will override those defined in the section above.
|
*/
// 'shop' => [
// 'path' => app_path(),
// 'namespace' => 'App',
// 'snake_attributes' => false,
// 'qualified_tables' => true,
// 'use' => [
// Reliese\Database\Eloquent\BitBooleans::class,
// ],
// 'except' => ['migrations'],
// 'only' => ['users'],
// // Table Specifics Bellow:
// 'user' => [
// // Don't use any default trait
// 'use' => [],
// ]
// ],
/*
|--------------------------------------------------------------------------
| Connection Specifics
|--------------------------------------------------------------------------
|
| In this section you may define the default configuration for each model
| that will be generated from a specific connection. You can also nest
| database and table specific configurations.
|
| You may wish to use connection specific config for setting a parent
| model with a read only setup, or enforcing a different set of rules
| for a connection, e.g. using snake_case naming over CamelCase naming.
|
| This supports nesting with the following key configuration values, in
| reverse precedence order (i.e. the last one found becomes the value).
|
| connections.{connection_name}.property
| connections.{connection_name}.{database_name}.property
| connections.{connection_name}.{table_name}.property
| connections.{connection_name}.{database_name}.{table_name}.property
|
| These values will override those defined in the section above.
|
*/
// 'connections' => [
// 'read_only_external' => [
// 'parent' => \App\Models\ReadOnlyModel::class,
// 'connection' => true,
// 'users' => [
// 'connection' => false,
// ],
// 'my_other_database' => [
// 'password_resets' => [
// 'connection' => false,
// ]
// ]
// ],
// ],
];