Skip to content

Commit 8f05abf

Browse files
committed
Add reserve key word option in config
1 parent fc7251c commit 8f05abf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/Commands/GeneratorCommand.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,17 @@ protected function getCollectionName($name = null)
188188
*/
189189
protected function getViewPath($name)
190190
{
191-
$name = implode('.', array_map('str_plural', explode('/', $name)));
191+
$pieces = explode('/', $name);
192+
193+
// dont plural if reserve word
194+
foreach ($pieces as $k => $value) {
195+
if (!in_array($value, config('generators.reserve_words'))) {
196+
$pieces[$k] = str_plural($pieces[$k]);
197+
}
198+
}
199+
200+
$name = implode('.', $pieces);
201+
//$name = implode('.', array_map('str_plural', explode('/', $name)));
192202

193203
return strtolower(rtrim(ltrim($name, '.'), '.'));
194204
}

src/config/config.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22

33
return [
44

5+
/*
6+
|--------------------------------------------------------------------------
7+
| The singular resource words that will not be pluralized
8+
| For Example: $ php artisan generate:resource admin.bar
9+
| The url will be /admin/bars and not /admins/bars
10+
|--------------------------------------------------------------------------
11+
*/
12+
13+
'reserve_words' => ['app', 'website', 'admin'],
14+
515
/*
616
|--------------------------------------------------------------------------
717
| The default keys and values for the settings of each type to be generated
818
|--------------------------------------------------------------------------
919
*/
1020

11-
'defaults' => [
21+
'defaults' => [
1222
'namespace' => '',
1323
'path' => '.app/',
1424
'prefix' => '',
@@ -25,7 +35,7 @@
2535
|--------------------------------------------------------------------------
2636
*/
2737

28-
'settings' => [
38+
'settings' => [
2939
'view' => ['path' => './resources/views/', 'file_type' => '.blade.php', 'directory_format' => 'strtolower', 'directory_namespace' => true],
3040
'model' => ['namespace' => '\Models', 'path' => './app/Models/'],
3141
'controller' => [
@@ -45,7 +55,7 @@
4555
|--------------------------------------------------------------------------
4656
*/
4757

48-
'resource_views' => [
58+
'resource_views' => [
4959
'view_index' => 'index',
5060
'view_add_edit' => 'add_edit',
5161
'view_show' => 'show',

0 commit comments

Comments
 (0)