Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Console/Commands/CrudControllerBackpackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 19 additions & 1 deletion src/Console/Commands/CrudModelBackpackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}
}
20 changes: 19 additions & 1 deletion src/Console/Commands/ModelBackpackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}
}