diff --git a/config/data.php b/config/data.php index f108d2df..2095a5d8 100644 --- a/config/data.php +++ b/config/data.php @@ -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', ]; diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 1cb0164d..ad776bc5 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -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 diff --git a/src/Commands/DataMakeCommand.php b/src/Commands/DataMakeCommand.php index 83d8b660..1b26dac1 100644 --- a/src/Commands/DataMakeCommand.php +++ b/src/Commands/DataMakeCommand.php @@ -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',