6
6
use Illuminate \Support \Facades \File ;
7
7
use Illuminate \Support \Facades \Schema ;
8
8
use Illuminate \Support \Str ;
9
+ use Illuminate \Support \Facades \DB ;
9
10
use Symfony \Component \Console \Input \InputArgument ;
10
11
use Symfony \Component \Console \Input \InputOption ;
11
12
@@ -53,6 +54,10 @@ protected function buildModelReplacements(array $replace) {
53
54
54
55
protected function buildValidationReplacements (array $ replace , $ fillables )
55
56
{
57
+ if (!$ fillables ) {
58
+ return $ replace ;
59
+ }
60
+
56
61
$ this ->table ([['fillables ' ]], array_chunk ($ fillables , 1 ));
57
62
$ this ->line ('<fg=cyan;options=bold>>>></> Validation rules should be separated by <options=bold>white space</>. ' );
58
63
$ this ->line ('Example: required min:6 max:100</> ' );
@@ -121,7 +126,11 @@ private function modelHasFillables($model) {
121
126
122
127
$ path = File::exists (app_path ('Models ' )) ? app_path ('Models ' ) : app_path ();
123
128
124
- if (File::exists ("$ path/ $ model.php " ) and resolve ($ this ->parseModel ($ model ))->getFillable ()) {
129
+ if (
130
+ File::exists ("$ path/ $ model.php " ) and
131
+ class_exists ($ this ->parseModel ($ model )) and
132
+ resolve ($ this ->parseModel ($ model ))->getFillable ()
133
+ ) {
125
134
return true ;
126
135
}
127
136
@@ -138,7 +147,7 @@ private function getFillables($model) {
138
147
139
148
if ($ this ->modelHasFillables ($ model )) {
140
149
return resolve ($ this ->parseModel ($ model ))->getFillable ();
141
- } elseif ([$ table , $ guarded ] = $ this ->modelHasSchemaAndGuarded ($ model )) {
150
+ } elseif ($ this -> isConnectedToDatabase () and [$ table , $ guarded ] = $ this ->modelHasSchemaAndGuarded ($ model )) {
142
151
$ schema = Schema::getColumnListing ($ table );
143
152
return array_diff ($ schema , $ guarded );
144
153
} else {
@@ -162,4 +171,12 @@ private function modelHasSchemaAndGuarded($model)
162
171
163
172
return [$ table , $ guarded ];
164
173
}
174
+
175
+ private function isConnectedToDatabase () {
176
+ try {
177
+ DB ::connection ()->getPdo ();
178
+ } catch (\Exception $ e ) {
179
+ return false ;
180
+ }
181
+ }
165
182
}
0 commit comments