diff --git a/src/Console/Commands/CrudControllerBackpackCommand.php b/src/Console/Commands/CrudControllerBackpackCommand.php index 76ee83a..26c3b30 100644 --- a/src/Console/Commands/CrudControllerBackpackCommand.php +++ b/src/Console/Commands/CrudControllerBackpackCommand.php @@ -137,8 +137,17 @@ protected function getAttributes($model) if (count($model->getFillable())) { $attributes = $model->getFillable(); } else { + $driver = \Schema::getConnection()->getConfig('driver'); + // otherwise, if guarded is used, just pick up the columns straight from the bd table - $attributes = \Schema::getColumnListing($model->getTable()); + switch ($driver) { + case 'mongodb': + $attributes = []; + break; + default: + $attributes = \Schema::getColumnListing($model->getTable()); + break; + } } return $attributes; diff --git a/src/Console/Commands/CrudModelBackpackCommand.php b/src/Console/Commands/CrudModelBackpackCommand.php index 1e67760..d28570b 100644 --- a/src/Console/Commands/CrudModelBackpackCommand.php +++ b/src/Console/Commands/CrudModelBackpackCommand.php @@ -173,6 +173,24 @@ protected function replaceTable(&$stub, $name) return $this; } + /** + * Replace Model on MongoDB. + * + * @param string $stub + * @param string $name + * @return string + */ + protected function replaceDriverDB(&$stub) + { + $driver = \Schema::getConnection()->getConfig('driver'); + + if ($driver === 'mongodb') { + $stub = str_replace(\Illuminate\Database\Eloquent\Model::class, \Jenssegers\Mongodb\Eloquent\Model::class, $stub); + } + + return $this; + } + /** * Build the class with the given name. * @@ -183,6 +201,6 @@ protected function buildClass($name) { $stub = $this->files->get($this->getStub()); - return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceClass($stub, $name); + return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceDriverDB($stub)->replaceClass($stub, $name); } } diff --git a/src/Console/Commands/ModelBackpackCommand.php b/src/Console/Commands/ModelBackpackCommand.php index 7fe7a81..507a36d 100644 --- a/src/Console/Commands/ModelBackpackCommand.php +++ b/src/Console/Commands/ModelBackpackCommand.php @@ -78,6 +78,24 @@ protected function replaceTable(&$stub, $name) return $this; } + /** + * Replace Model on MongoDB. + * + * @param string $stub + * @param string $name + * @return string + */ + protected function replaceDriverDB(&$stub) + { + $driver = \Schema::getConnection()->getConfig('driver'); + + if ($driver === 'mongodb') { + $stub = str_replace(\Illuminate\Database\Eloquent\Model::class, \Jenssegers\Mongodb\Eloquent\Model::class, $stub); + } + + return $this; + } + /** * Build the class with the given name. * @@ -88,6 +106,6 @@ protected function buildClass($name) { $stub = $this->files->get($this->getStub()); - return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceClass($stub, $name); + return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceDriverDB($stub)->replaceClass($stub, $name); } }