@@ -22,59 +22,44 @@ public function __construct()
22
22
23
23
public function generate ()
24
24
{
25
+ $ variables = [];
26
+
25
27
switch ($ this ->config ->tableType ) {
26
28
case 'blade ' :
27
29
if ($ this ->config ->options ->repositoryPattern ) {
28
- $ templateName = 'repository.controller ' ;
30
+ $ viewName = 'repository.controller ' ;
29
31
} else {
30
- $ templateName = 'model.controller ' ;
31
- }
32
- if ($ this ->config ->isLocalizedTemplates ()) {
33
- $ templateName .= '_locale ' ;
32
+ $ viewName = 'model.controller ' ;
34
33
}
35
34
36
- $ templateData = get_template ("scaffold.controller. $ templateName " , 'laravel-generator ' );
37
-
38
- $ templateData = str_replace ('$RENDER_TYPE$ ' , 'paginate(10) ' , $ templateData );
35
+ $ variables ['renderType ' ] = 'paginate(10) ' ;
39
36
break ;
40
37
41
38
case 'datatables ' :
42
39
if ($ this ->config ->options ->repositoryPattern ) {
43
- $ templateName = 'repository.datatable.controller ' ;
40
+ $ viewName = 'repository.datatable.controller ' ;
44
41
} else {
45
- $ templateName = 'model.datatable.controller ' ;
42
+ $ viewName = 'model.datatable.controller ' ;
46
43
}
47
44
48
- if ($ this ->config ->isLocalizedTemplates ()) {
49
- $ templateName .= '_locale ' ;
50
- }
51
-
52
- $ templateData = get_template ("scaffold.controller. $ templateName " , 'laravel-generator ' );
53
-
54
45
$ this ->generateDataTable ();
55
46
break ;
56
47
57
48
case 'livewire ' :
58
49
if ($ this ->config ->options ->repositoryPattern ) {
59
- $ templateName = 'repository.livewire.controller ' ;
50
+ $ viewName = 'repository.livewire.controller ' ;
60
51
} else {
61
- $ templateName = 'model.livewire.controller ' ;
62
- }
63
-
64
- if ($ this ->config ->isLocalizedTemplates ()) {
65
- $ templateName .= '_locale ' ;
52
+ $ viewName = 'model.livewire.controller ' ;
66
53
}
67
54
68
- $ templateData = get_template ("scaffold.controller. $ templateName " , 'laravel-generator ' );
69
-
70
55
$ this ->generateLivewireTable ();
71
56
break ;
72
57
73
58
default :
74
59
throw new Exception ('Invalid Table Type ' );
75
60
}
76
61
77
- $ templateData = fill_template ( $ this -> config -> dynamicVars , $ templateData );
62
+ $ templateData = view ( ' laravel-generator::scaffold.controller. ' . $ viewName , $ variables )-> render ( );
78
63
79
64
g_filesystem ()->createFile ($ this ->path .$ this ->fileName , $ templateData );
80
65
@@ -84,20 +69,9 @@ public function generate()
84
69
85
70
private function generateDataTable ()
86
71
{
87
- $ templateName = 'table.datatable ' ;
88
- if ($ this ->config ->isLocalizedTemplates ()) {
89
- $ templateName .= '_locale ' ;
90
- }
91
-
92
- $ templateData = get_template ('scaffold. ' .$ templateName , 'laravel-generator ' );
93
-
94
- $ templateData = fill_template ($ this ->config ->dynamicVars , $ templateData );
95
-
96
- $ templateData = str_replace (
97
- '$DATATABLE_COLUMNS$ ' ,
98
- implode (', ' .infy_nl_tab (1 , 3 ), $ this ->generateDataTableColumns ()),
99
- $ templateData
100
- );
72
+ $ templateData = view ('laravel-generator::scaffold.table.datatable ' , [
73
+ 'columns ' => implode (', ' .infy_nl_tab (1 , 3 ), $ this ->generateDataTableColumns ())
74
+ ])->render ();
101
75
102
76
$ path = $ this ->config ->paths ->dataTables ;
103
77
@@ -111,20 +85,9 @@ private function generateDataTable()
111
85
112
86
private function generateLivewireTable ()
113
87
{
114
- $ templateName = 'table.livewire ' ;
115
- if ($ this ->config ->isLocalizedTemplates ()) {
116
- $ templateName .= '_locale ' ;
117
- }
118
-
119
- $ templateData = get_template ('scaffold. ' .$ templateName , 'laravel-generator ' );
120
-
121
- $ templateData = fill_template ($ this ->config ->dynamicVars , $ templateData );
122
-
123
- $ templateData = str_replace (
124
- '$LIVEWIRE_COLUMNS$ ' ,
125
- implode (', ' .infy_nl_tab (1 , 3 ), $ this ->generateLivewireTableColumns ()),
126
- $ templateData
127
- );
88
+ $ templateData = view ('laravel-generator::scaffold.table.livewire ' , [
89
+ 'columns ' => implode (', ' .infy_nl_tab (1 , 3 ), $ this ->generateLivewireTableColumns ())
90
+ ])->render ();
128
91
129
92
$ path = $ this ->config ->paths ->livewireTables ;
130
93
@@ -138,38 +101,16 @@ private function generateLivewireTable()
138
101
139
102
private function generateDataTableColumns (): array
140
103
{
141
- $ templateName = 'table.datatable.column ' ;
142
- if ($ this ->config ->isLocalizedTemplates ()) {
143
- $ templateName .= '_locale ' ;
144
- }
145
- $ headerFieldTemplate = get_template ('scaffold.views. ' .$ templateName , $ this ->templateType );
146
-
147
104
$ dataTableColumns = [];
148
105
foreach ($ this ->config ->fields as $ field ) {
149
106
if (!$ field ->inIndex ) {
150
107
continue ;
151
108
}
152
109
153
- if ($ this ->config ->isLocalizedTemplates () && !$ field ->isSearchable ) {
154
- $ headerFieldTemplate = str_replace ('$SEARCHABLE$ ' , ",'searchable' => false " , $ headerFieldTemplate );
155
- }
156
-
157
- $ fieldTemplate = fill_template_with_field_data (
158
- $ this ->config ->dynamicVars ,
159
- ['$FIELD_NAME_TITLE$ ' => 'fieldTitle ' , '$FIELD_NAME$ ' => 'name ' ],
160
- $ headerFieldTemplate ,
161
- $ field
162
- );
163
-
164
- if ($ field ->isSearchable ) {
165
- $ dataTableColumns [] = $ fieldTemplate ;
166
- } else {
167
- if ($ this ->config ->isLocalizedTemplates ()) {
168
- $ dataTableColumns [] = $ fieldTemplate ;
169
- } else {
170
- $ dataTableColumns [] = "' " .$ field ->name ."' => ['searchable' => false] " ;
171
- }
172
- }
110
+ $ dataTableColumns [] = trim (view (
111
+ $ this ->templateType .'::templates.scaffold.table.datatable.column ' ,
112
+ $ field ->variables ()
113
+ )->render ());
173
114
}
174
115
175
116
return $ dataTableColumns ;
@@ -184,14 +125,8 @@ private function generateLivewireTableColumns(): array
184
125
continue ;
185
126
}
186
127
187
- $ fieldTemplate = 'Column::make("$FIELD_NAME_TITLE$", "$FIELD_NAME$") ' .PHP_EOL .infy_tabs (4 ).'->sortable() ' ;
188
-
189
- $ fieldTemplate = fill_template_with_field_data (
190
- $ this ->config ->dynamicVars ,
191
- ['$FIELD_NAME_TITLE$ ' => 'fieldTitle ' , '$FIELD_NAME$ ' => 'name ' ],
192
- $ fieldTemplate ,
193
- $ field
194
- );
128
+ $ fieldTemplate = 'Column::make(" ' .$ field ->getTitle ().'", " ' .$ field ->name .'") ' .PHP_EOL ;
129
+ $ fieldTemplate .= infy_tabs (4 ).'->sortable() ' ;
195
130
196
131
if ($ field ->isSearchable ) {
197
132
$ fieldTemplate .= PHP_EOL .infy_tabs (4 ).'->searchable() ' ;
0 commit comments