Skip to content

Commit 983dc66

Browse files
authored
fix: #853 Support to add Custom modal name in select Dropdown (#859)
1 parent b00c7c6 commit 983dc66

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/Generators/Scaffold/ViewGenerator.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,17 @@ private function generateFields()
274274
}
275275
$columns = substr_replace($columns, '', -1); // remove last ,
276276

277-
$selectTable = $field->htmlValues[0];
277+
$htmlValues = explode(',', $field->htmlValues[0]);
278+
$selectTable = $htmlValues[0];
279+
$modalName = null;
280+
if (count($htmlValues) == 2) {
281+
$modalName = $htmlValues[1];
282+
}
283+
278284
$tableName = $this->commandData->config->tableName;
279285
$variableName = Str::singular($selectTable).'Items'; // e.g $userItems
280286

281-
$fieldTemplate = $this->generateViewComposer($tableName, $variableName, $columns, $selectTable);
287+
$fieldTemplate = $this->generateViewComposer($tableName, $variableName, $columns, $selectTable, $modalName);
282288
}
283289

284290
if (!empty($fieldTemplate)) {
@@ -301,13 +307,13 @@ private function generateFields()
301307
$this->commandData->commandInfo('field.blade.php created');
302308
}
303309

304-
private function generateViewComposer($tableName, $variableName, $columns, $selectTable)
310+
private function generateViewComposer($tableName, $variableName, $columns, $selectTable, $modelName = null)
305311
{
306312
$fieldTemplate = get_template('scaffold.fields.select', $this->templateType);
307313

308314
$viewServiceProvider = new ViewServiceProviderGenerator($this->commandData);
309315
$viewServiceProvider->generate();
310-
$viewServiceProvider->addViewVariables($tableName.'.fields', $variableName, $columns, $selectTable);
316+
$viewServiceProvider->addViewVariables($tableName.'.fields', $variableName, $columns, $selectTable, $modelName);
311317

312318
$fieldTemplate = str_replace(
313319
'$INPUT_ARR$',

src/Generators/ViewServiceProviderGenerator.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,19 @@ public function generate()
4343
}
4444

4545
/**
46-
* @param string $views
47-
* @param string $variableName
48-
* @param string $columns
49-
* @param string $tableName
46+
* @param string $views
47+
* @param string $variableName
48+
* @param string $columns
49+
* @param string $tableName
50+
* @param string|null $modelName
5051
*/
51-
public function addViewVariables($views, $variableName, $columns, $tableName)
52+
public function addViewVariables($views, $variableName, $columns, $tableName, $modelName = null)
5253
{
53-
$model = model_name_from_table_name($tableName);
54+
if (!empty($modelName)) {
55+
$model = $modelName;
56+
} else {
57+
$model = model_name_from_table_name($tableName);
58+
}
5459

5560
$this->commandData->addDynamicVariable('$COMPOSER_VIEWS$', $views);
5661
$this->commandData->addDynamicVariable('$COMPOSER_VIEW_VARIABLE$', $variableName);

0 commit comments

Comments
 (0)