How to configure crudmaker to generate controllers as single names rather than plural?
shabaz-ejaz opened this issue · comments
Lets say I have the following command:
php artisan crudmaker:new Book --api --migration --schema="id:increments,title:string,author:string"
When I run this command it generates the following files:
app/Http/Controllers/Api/BooksController.php
app/Http/Controllers/BooksController.php
app/Http/Requests/BookCreateRequest.php
app/Http/Requests/BookUpdateRequest.php
app/Models/Book/Book.php
app/Services/BookService.php
resources/views/books/create.blade.php
resources/views/books/edit.blade.php
resources/views/books/index.blade.php
resources/views/books/show.blade.php
database/migrations/create_books_table.php
tests/BookIntegrationTest.php
tests/BookServiceTest.php
Notice the first Api Controller: app/Http/Controllers/Api/BooksController.php
Why is it creating the controllers in the plural form? How do I change this so it uses single naming convention for controllers?
Here is my config file:
<?php
return [
'template_source' => app()->basePath().'/resources/crudmaker',
'single' => [
'_path_facade_' => app()->path().'/Facades',
'_path_service_' => app()->path().'/Services',
'_path_model_' => app()->path().'/Models',
'_path_controller_' => app()->path().'/Http/Controllers/',
'_path_api_controller_' => app()->path().'/Http/Controllers/Api',
'_path_views_' => app()->basePath().'/resources/views',
'_path_tests_' => app()->basePath().'/tests',
'_path_request_' => app()->path().'/Http/Requests/',
'_path_routes_' => app()->basePath().'/routes/web.php',
'_path_api_routes_' => app()->basePath().'/routes/api.php',
'routes_prefix' => '',
'routes_suffix' => '',
'_app_namespace_' => app_namespace(),
'_namespace_services_' => app_namespace().'Services',
'_namespace_facade_' => app_namespace().'Facades',
'_namespace_model_' => app_namespace().'Models',
'_namespace_controller_' => app_namespace().'Http\Controllers',
'_namespace_api_controller_' => app_namespace().'Http\Controllers\Api',
'_namespace_request_' => app_namespace().'Http\Requests',
],
'sectioned' => [
'_path_facade_' => app()->path().'/Facades',
'_path_service_' => app()->path().'/Services/_section_',
'_path_model_' => app()->path().'/Models/_section_',
'_path_controller_' => app()->path().'/Http/Controllers/_section_/',
'_path_api_controller_' => app()->path().'/Http/Controllers/Api/_section_/',
'_path_views_' => app()->basePath().'/resources/views/_sectionLowerCase_',
'_path_tests_' => app()->basePath().'/tests',
'_path_request_' => app()->path().'/Http/Requests/_section_',
'_path_routes_' => app()->basePath().'/routes/web.php',
'_path_api_routes_' => app()->basePath().'/routes/api.php',
'routes_prefix' => "\n\nRoute::group(['namespace' => '_section_', 'prefix' => '_sectionLowerCase_', 'as' => '_sectionLowerCase_', 'middleware' => ['web']], function () { \n",
'routes_suffix' => "\n});",
'_app_namespace_' => app_namespace(),
'_namespace_services_' => app_namespace().'Services',
'_namespace_facade_' => app_namespace().'Facades',
'_namespace_model_' => app_namespace().'Models\_section_',
'_namespace_controller_' => app_namespace().'Http\Controllers',
'_namespace_api_controller_' => app_namespace().'Http\Controllers\Api',
'_namespace_request_' => app_namespace().'Http\Requests',
],
];
Any updates on this?
Sorry for the delay, you could expand on the config by exploring CrudMaker/src/Services/ConfigService.php:58
where you will see the basicConfig
method, you can override all those config methods to remove the pluralizing of Controllers.