Skip to content

Commit

Permalink
Update make command
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jun 2, 2023
1 parent b6fd837 commit ec81357
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
12 changes: 0 additions & 12 deletions config/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,4 @@
* which will only enable the caster locally.
*/
'var_dumper_caster_mode' => 'development',

/*
* This configuration property is used to override default namespace to store data objects.
* The --namespace option has the higher priority.
*/
'namespace' => 'Data',

/*
* This configuration property is used for override default suffix in data objects class names.
* The --suffix option has higher priority.
*/
'suffix' => 'Data',
];
27 changes: 27 additions & 0 deletions docs/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ By default, this command puts data objects in the `App\Data` namespace, this can
php artisan make:data PostData --namespace=DataTransferObjects
```

By default, the command creates a new data object within the `\App\Data` namespace and suffixes the class with `Data`, this can be changed by adding the following lines to the `data.php` config file:

```php
'commands' => [
/*
* Provides default configuration for the `make:data` command. These settings can be overridden with options
* passed directly to the `make:data` command for generating single Data classes, or if not set they will
* automatically fall back to these defaults. See `php artisan make:data --help` for more information
*/
'make' => [
/*
* The default namespace for generated Data classes. This exists under the application's root namespace,
* so the default 'Data` will end up as '\App\Data', and generated Data classes will be placed in the
* app/Data/ folder. Data classes can live anywhere, but this is where `make:data` will put them.
*/
'namespace' => 'DataTransferObjects',

/*
* This suffix will be appended to all data classes generated by make:data, so that they do are less likely
* to conflict with other related classes, controllers, or models with a similar name without resorting
* to adding an alias on to the end of the Data object. Set to a blank string (not null) to disable.
*/
'suffix' => 'DTO',
],
]
```

## Using requests and casts

Now let's say we have a Laravel request coming from the front with these properties. Our controller would then look like
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/DataMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ protected function getOptions(): array
'N',
InputOption::VALUE_REQUIRED,
'The namespace (under \App) to place this Data class.',
config('data.namespace', 'Data'),
config('data.commands.make.namespace', 'Data'),
],
[
'suffix',
's',
InputOption::VALUE_REQUIRED,
'Suffix the class with this value.',
config('data.suffix', 'Data'),
config('data.commands.make.suffix', 'Data'),
],
[
'force',
Expand Down

0 comments on commit ec81357

Please sign in to comment.