Skip to content

Commit 6097524

Browse files
committed
Fixing class not found issue
1 parent 642548c commit 6097524

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/CrudGeneratorMakeCommand.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\File;
77
use Illuminate\Support\Facades\Schema;
88
use Illuminate\Support\Str;
9+
use Illuminate\Support\Facades\DB;
910
use Symfony\Component\Console\Input\InputArgument;
1011
use Symfony\Component\Console\Input\InputOption;
1112

@@ -53,6 +54,10 @@ protected function buildModelReplacements(array $replace) {
5354

5455
protected function buildValidationReplacements(array $replace, $fillables)
5556
{
57+
if (!$fillables) {
58+
return $replace;
59+
}
60+
5661
$this->table([['fillables']], array_chunk($fillables, 1));
5762
$this->line('<fg=cyan;options=bold>>>></> Validation rules should be separated by <options=bold>white space</>.');
5863
$this->line('Example: required min:6 max:100</>');
@@ -121,7 +126,11 @@ private function modelHasFillables($model) {
121126

122127
$path = File::exists(app_path('Models')) ? app_path('Models') : app_path();
123128

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+
) {
125134
return true;
126135
}
127136

@@ -138,7 +147,7 @@ private function getFillables($model) {
138147

139148
if($this->modelHasFillables($model)) {
140149
return resolve($this->parseModel($model))->getFillable();
141-
} elseif([$table, $guarded] = $this->modelHasSchemaAndGuarded($model)) {
150+
} elseif($this->isConnectedToDatabase() and [$table, $guarded] = $this->modelHasSchemaAndGuarded($model)) {
142151
$schema = Schema::getColumnListing($table);
143152
return array_diff($schema, $guarded);
144153
} else {
@@ -162,4 +171,12 @@ private function modelHasSchemaAndGuarded($model)
162171

163172
return [$table, $guarded];
164173
}
174+
175+
private function isConnectedToDatabase() {
176+
try {
177+
DB::connection()->getPdo();
178+
} catch (\Exception $e) {
179+
return false;
180+
}
181+
}
165182
}

0 commit comments

Comments
 (0)