Skip to content

Commit

Permalink
Fix bugs and making compatible with laravel 9
Browse files Browse the repository at this point in the history
  • Loading branch information
mehradsadeghi committed Mar 10, 2022
1 parent 6097524 commit 985e828
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"php": "^7.1|^8.0",
"laravel/framework": "5.*|6.*|7.*|8.*"
"laravel/framework": "5.*|6.*|7.*|8.*|9.*"
},
"require-dev": {
"orchestra/testbench": "^4.0"
Expand All @@ -45,4 +45,4 @@
]
}
}
}
}
37 changes: 31 additions & 6 deletions src/CrudGeneratorMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Mehradsadeghi\CrudGenerator;

use Illuminate\Routing\Console\ControllerMakeCommand;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Exception;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Console\Input\InputArgument;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Illuminate\Routing\Console\ControllerMakeCommand;

class CrudGeneratorMakeCommand extends ControllerMakeCommand {

Expand Down Expand Up @@ -38,7 +39,31 @@ protected function buildClass($name) {
}

protected function buildModelReplacements(array $replace) {
$replacements = parent::buildModelReplacements($replace);
$modelClass = $this->parseModel($this->option('model'));

try {
if (! class_exists($modelClass)) {
if ($this->confirm("A {$modelClass} model does not exist. Do you want to generate it?", true)) {
$this->call('make:model', ['name' => $modelClass]);
}
}
} catch (Exception $exception) {
if ($this->confirm("A {$modelClass} model does not exist. Do you want to generate it?", true)) {
$this->call('make:model', ['name' => $modelClass]);
}
}

$replacements = array_merge($replace, [
'DummyFullModelClass' => $modelClass,
'{{ namespacedModel }}' => $modelClass,
'{{namespacedModel}}' => $modelClass,
'DummyModelClass' => class_basename($modelClass),
'{{ model }}' => class_basename($modelClass),
'{{model}}' => class_basename($modelClass),
'DummyModelVariable' => lcfirst(class_basename($modelClass)),
'{{ modelVariable }}' => lcfirst(class_basename($modelClass)),
'{{modelVariable}}' => lcfirst(class_basename($modelClass)),
]);

return [
'{{ modelPluralVariable }}' => Str::plural(lcfirst(class_basename($this->option('model')))),
Expand Down Expand Up @@ -175,7 +200,7 @@ private function modelHasSchemaAndGuarded($model)
private function isConnectedToDatabase() {
try {
DB::connection()->getPdo();
} catch (\Exception $e) {
} catch (Exception $e) {
return false;
}
}
Expand Down

0 comments on commit 985e828

Please sign in to comment.