From 9b3ef0df2f13e200db2ab9c90003dfcf77f2b529 Mon Sep 17 00:00:00 2001 From: Artyom Osepyan Date: Wed, 29 Oct 2025 21:10:30 +0300 Subject: [PATCH 1/3] feat: add resource not found exception Refs: https://github.com/RonasIT/laravel-entity-generator/issues/179 --- src/Exceptions/AbstractResourceException.php | 16 ++++++++++++++ .../ResourceAlreadyExistsException.php | 18 ++++----------- src/Exceptions/ResourceNotExistsException.php | 15 +++++++++++++ src/Generators/ControllerGenerator.php | 9 +------- src/Generators/EntityGenerator.php | 22 ++++++++++++++----- src/Generators/FactoryGenerator.php | 10 +-------- src/Generators/ModelGenerator.php | 10 +-------- src/Generators/NovaResourceGenerator.php | 10 +-------- src/Generators/RepositoryGenerator.php | 10 +-------- src/Generators/ServiceGenerator.php | 9 +------- tests/ControllerGeneratorTest.php | 12 +++++----- tests/FactoryGeneratorTest.php | 17 +++++++------- tests/ModelGeneratorTest.php | 11 +++++----- tests/NovaResourceGeneratorTest.php | 13 +++++------ tests/RepositoryGeneratorTest.php | 9 ++++---- tests/ServiceGeneratorTest.php | 9 ++++---- 16 files changed, 90 insertions(+), 110 deletions(-) create mode 100644 src/Exceptions/AbstractResourceException.php create mode 100644 src/Exceptions/ResourceNotExistsException.php diff --git a/src/Exceptions/AbstractResourceException.php b/src/Exceptions/AbstractResourceException.php new file mode 100644 index 00000000..272eb05b --- /dev/null +++ b/src/Exceptions/AbstractResourceException.php @@ -0,0 +1,16 @@ +getEntity(); - - parent::__construct("Cannot create {$entity} cause it already exists. Remove {$this->filePath} and run command again."); - } - - protected function getEntity(): string - { - $fileName = Str::afterLast($this->filePath, '/'); + $entity = $this->getEntity($filePath); - return Str::before($fileName, '.php'); + parent::__construct("Cannot create {$entity} cause it already exists. Remove {$filePath} and run command again."); } } diff --git a/src/Exceptions/ResourceNotExistsException.php b/src/Exceptions/ResourceNotExistsException.php new file mode 100644 index 00000000..09fac238 --- /dev/null +++ b/src/Exceptions/ResourceNotExistsException.php @@ -0,0 +1,15 @@ +getEntity($filePath); + + parent::__construct("Cannot create {$entity} cause {$resource} does not exist. Create {$filePath} and run command again."); + } +} \ No newline at end of file diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index 1820db49..b7b3c241 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -3,7 +3,6 @@ namespace RonasIT\Support\Generators; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; @@ -17,13 +16,7 @@ public function generate(): void throw new ResourceAlreadyExistsException($path); } - if (!$this->classExists('services', "{$this->model}Service")) { - $this->throwFailureException( - ClassNotExistsException::class, - "Cannot create {$this->model}Controller cause {$this->model}Service does not exists.", - "Create a {$this->model}Service by himself.", - ); - } + $this->checkResourceNotExists('services', "{$this->model}Controller", "{$this->model}Service"); if (!$this->isStubExists('controller')) { return; diff --git a/src/Generators/EntityGenerator.php b/src/Generators/EntityGenerator.php index 74455dc5..71da85f8 100644 --- a/src/Generators/EntityGenerator.php +++ b/src/Generators/EntityGenerator.php @@ -2,18 +2,19 @@ namespace RonasIT\Support\Generators; -use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Filesystem\Filesystem; +use Throwable; +use ReflectionClass; +use ReflectionMethod; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; +use Illuminate\Support\Facades\DB; +use Illuminate\Filesystem\Filesystem; use RonasIT\Support\DTO\RelationsDTO; use RonasIT\Support\Events\WarningEvent; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use RonasIT\Support\Exceptions\ClassNotExistsException; +use RonasIT\Support\Exceptions\ResourceNotExistsException; use RonasIT\Support\Exceptions\IncorrectClassPathException; -use Throwable; -use ReflectionMethod; -use ReflectionClass; /** * @property Filesystem $fs @@ -308,4 +309,13 @@ protected function pathToNamespace(string $name): string { return ucwords(Str::replace('/', '\\', $name), '\\'); } + + protected function checkResourceNotExists(string $path, string $entity, string $resourceName, ?string $subFolder = null): void + { + if (!$this->classExists($path, $resourceName, $subFolder)) { + $filePath = $this->getClassPath($path, $resourceName, $subFolder); + + throw new ResourceNotExistsException($entity, $filePath); + } + } } diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 83308d35..ee46de77 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -7,7 +7,6 @@ use Illuminate\Support\Str; use InvalidArgumentException; use RonasIT\Support\Exceptions\FakerMethodNotFoundException; -use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; @@ -27,14 +26,7 @@ class FactoryGenerator extends EntityGenerator public function generate(): void { - if (!$this->classExists('models', $this->model, $this->modelSubFolder)) { - // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179 - $this->throwFailureException( - exceptionClass: ClassNotExistsException::class, - failureMessage: "Cannot create {$this->model}Factory cause {$this->model} Model does not exists.", - recommendedMessage: "Create a {$this->model} Model by itself or run command 'php artisan make:entity {$this->model} --only-model'.", - ); - } + $this->checkResourceNotExists('models', "{$this->model}Factory", $this->model, $this->modelSubFolder); if ($this->classExists('factories', "{$this->model}Factory")) { $path = $this->getClassPath('factories', "{$this->model}Factory"); diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index d25f17ee..b5bd7bce 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -4,7 +4,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; -use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; @@ -65,14 +64,7 @@ public function prepareRelatedModels(): void foreach ($this->relations as $type => $relationsByType) { foreach ($relationsByType as $relation) { - if (!$this->classExists('models', $relation)) { - // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179 - $this->throwFailureException( - exceptionClass: ClassNotExistsException::class, - failureMessage: "Cannot create {$this->model} Model cause relation model {$relation} does not exist.", - recommendedMessage: "Create the {$relation} Model by himself or run command 'php artisan make:entity {$relation} --only-model'.", - ); - } + $this->checkResourceNotExists('models', $this->model, $relation); $content = $this->getModelContent($relation); diff --git a/src/Generators/NovaResourceGenerator.php b/src/Generators/NovaResourceGenerator.php index d52ed334..d79e93ae 100644 --- a/src/Generators/NovaResourceGenerator.php +++ b/src/Generators/NovaResourceGenerator.php @@ -7,7 +7,6 @@ use Illuminate\Support\Facades\DB; use Laravel\Nova\NovaServiceProvider; use RonasIT\Support\Events\SuccessCreateMessage; -use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; use RonasIT\Support\Support\CommandLineNovaField; use RonasIT\Support\Support\DatabaseNovaField; @@ -55,14 +54,7 @@ class NovaResourceGenerator extends EntityGenerator public function generate(): void { if (class_exists(NovaServiceProvider::class)) { - if (!$this->classExists('models', $this->model, $this->modelSubFolder)) { - // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179 - $this->throwFailureException( - ClassNotExistsException::class, - "Cannot create {$this->model} Nova resource cause {$this->model} Model does not exists.", - "Create a {$this->model} Model by himself or run command 'php artisan make:entity {$this->model} --only-model'." - ); - } + $this->checkResourceNotExists('models', "{$this->model} Nova resource", $this->model, $this->modelSubFolder); if ($this->classExists('nova', "{$this->model}Resource")) { $path = $this->getClassPath('nova', "{$this->model}Resource", $this->modelSubFolder); diff --git a/src/Generators/RepositoryGenerator.php b/src/Generators/RepositoryGenerator.php index d051ca8b..828780c3 100644 --- a/src/Generators/RepositoryGenerator.php +++ b/src/Generators/RepositoryGenerator.php @@ -2,21 +2,13 @@ namespace RonasIT\Support\Generators; -use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Events\SuccessCreateMessage; class RepositoryGenerator extends EntityGenerator { public function generate(): void { - if (!$this->classExists('models', $this->model, $this->modelSubFolder)) { - // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179 - $this->throwFailureException( - ClassNotExistsException::class, - "Cannot create {$this->model}Repository cause {$this->model} Model does not exists.", - "Create a {$this->model} Model by himself or run command 'php artisan make:entity {$this->model} --only-model'." - ); - } + $this->checkResourceNotExists('models', "{$this->model}Repository", $this->model, $this->modelSubFolder); if (!$this->isStubExists('repository')) { return; diff --git a/src/Generators/ServiceGenerator.php b/src/Generators/ServiceGenerator.php index bae74d5c..0dbf10b7 100644 --- a/src/Generators/ServiceGenerator.php +++ b/src/Generators/ServiceGenerator.php @@ -3,20 +3,13 @@ namespace RonasIT\Support\Generators; use Illuminate\Support\Arr; -use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Events\SuccessCreateMessage; class ServiceGenerator extends EntityGenerator { public function generate(): void { - if (!$this->classExists('repositories', "{$this->model}Repository")) { - $this->throwFailureException( - exceptionClass: ClassNotExistsException::class, - failureMessage: "Cannot create {$this->model}Service cause {$this->model}Repository does not exists.", - recommendedMessage: "Create a {$this->model}Repository by himself or run command 'php artisan make:entity {$this->model} --only-repository'.", - ); - } + $this->checkResourceNotExists('repositories', "{$this->model}Service", "{$this->model}Repository"); if (!$this->isStubExists('service')) { return; diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index 6c6fa7d2..1d428f2d 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -2,13 +2,13 @@ namespace RonasIT\Support\Tests; -use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Support\Facades\View; -use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; -use RonasIT\Support\Exceptions\ClassNotExistsException; -use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; +use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Generators\ControllerGenerator; +use Illuminate\Contracts\Filesystem\FileNotFoundException; +use RonasIT\Support\Exceptions\ResourceNotExistsException; +use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; use RonasIT\Support\Tests\Support\ControllerGeneratorTest\ControllerGeneratorMockTrait; class ControllerGeneratorTest extends TestCase @@ -46,8 +46,8 @@ public function testModelServiceNotExists() ]); $this->assertExceptionThrew( - className: ClassNotExistsException::class, - message: 'Cannot create PostController cause PostService does not exists. Create a PostService by himself.', + className: ResourceNotExistsException::class, + message: 'Cannot create PostController cause PostService does not exist. Create app/Services/PostService.php and run command again.', ); app(ControllerGenerator::class) diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index 60f46176..d62034ad 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -2,17 +2,17 @@ namespace RonasIT\Support\Tests; -use Illuminate\Support\Facades\Config; -use Illuminate\Support\Facades\Event; use Illuminate\View\ViewException; +use Illuminate\Support\Facades\Event; use RonasIT\Support\DTO\RelationsDTO; -use RonasIT\Support\Events\SuccessCreateMessage; +use Illuminate\Support\Facades\Config; use RonasIT\Support\Events\WarningEvent; -use RonasIT\Support\Exceptions\ClassNotExistsException; -use RonasIT\Support\Exceptions\IncorrectClassPathException; -use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; +use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Generators\FactoryGenerator; +use RonasIT\Support\Exceptions\ResourceNotExistsException; +use RonasIT\Support\Exceptions\IncorrectClassPathException; use RonasIT\Support\Tests\Support\Factory\FactoryMockTrait; +use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; class FactoryGeneratorTest extends TestCase { @@ -30,9 +30,8 @@ public function testModelNotExists() $this->mockFileSystemWithoutPostModel(); $this->assertExceptionThrew( - className: ClassNotExistsException::class, - message: "Cannot create PostFactory cause Post Model does not exists. " - . "Create a Post Model by itself or run command 'php artisan make:entity Post --only-model'.", + className: ResourceNotExistsException::class, + message: 'Cannot create PostFactory cause Post does not exist. Create app/Models/Post.php and run command again.', ); app(FactoryGenerator::class) diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index e2326b51..7cf651a6 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -3,13 +3,13 @@ namespace RonasIT\Support\Tests; use RonasIT\Support\DTO\RelationsDTO; -use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; -use RonasIT\Support\Exceptions\ClassNotExistsException; -use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; use RonasIT\Support\Generators\ModelGenerator; +use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Tests\Support\Model\ModelMockTrait; use Symfony\Component\Console\Exception\RuntimeException; +use RonasIT\Support\Exceptions\ResourceNotExistsException; +use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; class ModelGeneratorTest extends TestCase { @@ -44,9 +44,8 @@ public function testRelationModelMissing() $this->mockFileSystemWithoutCommentModel(); $this->assertExceptionThrew( - className: ClassNotExistsException::class, - message: "Cannot create Post Model cause relation model Comment does not exist. " - . "Create the Comment Model by himself or run command 'php artisan make:entity Comment --only-model'.", + className: ResourceNotExistsException::class, + message: 'Cannot create Post cause Comment does not exist. Create app/Models/Comment.php and run command again.', ); app(ModelGenerator::class) diff --git a/tests/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index 4efd66cd..300a2f5b 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -2,13 +2,13 @@ namespace RonasIT\Support\Tests; -use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; -use RonasIT\Support\Exceptions\ClassNotExistsException; -use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; +use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Generators\NovaResourceGenerator; -use RonasIT\Support\Tests\Support\NovaResourceGeneratorTest\NovaResourceGeneratorMockTrait; +use RonasIT\Support\Exceptions\ResourceNotExistsException; +use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; use RonasIT\Support\Tests\Support\NovaResourceGeneratorTest\Post; +use RonasIT\Support\Tests\Support\NovaResourceGeneratorTest\NovaResourceGeneratorMockTrait; class NovaResourceGeneratorTest extends TestCase { @@ -42,9 +42,8 @@ public function testCreateNovaResourceWithMissingModel() $this->mockNovaServiceProviderExists(); $this->assertExceptionThrew( - className: ClassNotExistsException::class, - message: 'Cannot create Post Nova resource cause Post Model does not exists. ' - . "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'" + className: ResourceNotExistsException::class, + message: 'Cannot create Post Nova resource cause Post does not exist. Create app/Models/Post.php and run command again.' ); app(NovaResourceGenerator::class) diff --git a/tests/RepositoryGeneratorTest.php b/tests/RepositoryGeneratorTest.php index 730f063c..1c3e514f 100644 --- a/tests/RepositoryGeneratorTest.php +++ b/tests/RepositoryGeneratorTest.php @@ -2,10 +2,10 @@ namespace RonasIT\Support\Tests; -use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; -use RonasIT\Support\Exceptions\ClassNotExistsException; +use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Generators\RepositoryGenerator; +use RonasIT\Support\Exceptions\ResourceNotExistsException; use RonasIT\Support\Tests\Support\Repository\RepositoryMockTrait; class RepositoryGeneratorTest extends TestCase @@ -26,9 +26,8 @@ public function testModelNotExist() ]); $this->assertExceptionThrew( - className: ClassNotExistsException::class, - message: "Cannot create PostRepository cause Post Model does not exists. " - . "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'.", + className: ResourceNotExistsException::class, + message: 'Cannot create PostRepository cause Post does not exist. Create app/Models/Post.php and run command again.', ); app(RepositoryGenerator::class) diff --git a/tests/ServiceGeneratorTest.php b/tests/ServiceGeneratorTest.php index a4ac77df..e2484bfc 100644 --- a/tests/ServiceGeneratorTest.php +++ b/tests/ServiceGeneratorTest.php @@ -4,11 +4,11 @@ use Illuminate\Support\Facades\Event; use RonasIT\Support\DTO\RelationsDTO; -use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; -use RonasIT\Support\Exceptions\ClassNotExistsException; +use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Generators\ServiceGenerator; use RonasIT\Support\Tests\Support\GeneratorMockTrait; +use RonasIT\Support\Exceptions\ResourceNotExistsException; class ServiceGeneratorTest extends TestCase { @@ -21,9 +21,8 @@ public function testMissingRepository() ]); $this->assertExceptionThrew( - className: ClassNotExistsException::class, - message: 'Cannot create PostService cause PostRepository does not exists. ' - . "Create a PostRepository by himself or run command 'php artisan make:entity Post --only-repository'", + className: ResourceNotExistsException::class, + message: 'Cannot create PostService cause PostRepository does not exist. Create app/Repositories/PostRepository.php and run command again.', ); app(ServiceGenerator::class) From 3137a003f42ae4499a5c483685ca03e4f8330357 Mon Sep 17 00:00:00 2001 From: Artyom Osepyan Date: Tue, 4 Nov 2025 17:21:34 +0300 Subject: [PATCH 2/3] fix: remarks from reviewer --- src/Exceptions/AbstractResourceException.php | 2 +- src/Exceptions/ResourceNotExistsException.php | 2 +- src/Generators/NovaResourceGenerator.php | 2 +- tests/NovaResourceGeneratorTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Exceptions/AbstractResourceException.php b/src/Exceptions/AbstractResourceException.php index 272eb05b..32ad3898 100644 --- a/src/Exceptions/AbstractResourceException.php +++ b/src/Exceptions/AbstractResourceException.php @@ -13,4 +13,4 @@ protected function getEntity(string $filePath): string return Str::before($fileName, '.php'); } -} \ No newline at end of file +} diff --git a/src/Exceptions/ResourceNotExistsException.php b/src/Exceptions/ResourceNotExistsException.php index 09fac238..5aecb276 100644 --- a/src/Exceptions/ResourceNotExistsException.php +++ b/src/Exceptions/ResourceNotExistsException.php @@ -12,4 +12,4 @@ public function __construct( parent::__construct("Cannot create {$entity} cause {$resource} does not exist. Create {$filePath} and run command again."); } -} \ No newline at end of file +} diff --git a/src/Generators/NovaResourceGenerator.php b/src/Generators/NovaResourceGenerator.php index 07d628a1..02c10a39 100644 --- a/src/Generators/NovaResourceGenerator.php +++ b/src/Generators/NovaResourceGenerator.php @@ -55,7 +55,7 @@ class NovaResourceGenerator extends EntityGenerator public function generate(): void { if (class_exists(NovaServiceProvider::class)) { - $this->checkResourceNotExists('models', "{$this->model} Nova resource", $this->model, $this->modelSubFolder); + $this->checkResourceNotExists('models', "{$this->model}Resource", $this->model, $this->modelSubFolder); $this->checkResourceExists('nova', "{$this->model}Resource", $this->modelSubFolder); diff --git a/tests/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index 7c74a1fb..55964eb9 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -43,7 +43,7 @@ public function testCreateNovaResourceWithMissingModel() $this->assertExceptionThrew( className: ResourceNotExistsException::class, - message: 'Cannot create Post Nova resource cause Post does not exist. Create app/Models/Post.php and run command again.' + message: 'Cannot create PostResource cause Post does not exist. Create app/Models/Post.php and run command again.' ); app(NovaResourceGenerator::class) From f6533e4a11025aeb5022849785e107f04f605258 Mon Sep 17 00:00:00 2001 From: Artyom Osepyan Date: Tue, 11 Nov 2025 10:32:30 +0300 Subject: [PATCH 3/3] fix: remarks from reviewer --- src/Exceptions/ResourceNotExistsException.php | 8 ++++---- src/Generators/EntityGenerator.php | 8 ++++---- src/Generators/NovaResourceGenerator.php | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Exceptions/ResourceNotExistsException.php b/src/Exceptions/ResourceNotExistsException.php index 5aecb276..e9398c33 100644 --- a/src/Exceptions/ResourceNotExistsException.php +++ b/src/Exceptions/ResourceNotExistsException.php @@ -5,11 +5,11 @@ class ResourceNotExistsException extends AbstractResourceException { public function __construct( - string $entity, - string $filePath, + string $createableResource, + string $requiredFilePath, ) { - $resource = $this->getEntity($filePath); + $resource = $this->getEntity($requiredFilePath); - parent::__construct("Cannot create {$entity} cause {$resource} does not exist. Create {$filePath} and run command again."); + parent::__construct("Cannot create {$createableResource} cause {$resource} does not exist. Create {$requiredFilePath} and run command again."); } } diff --git a/src/Generators/EntityGenerator.php b/src/Generators/EntityGenerator.php index 894e37d9..df50127f 100644 --- a/src/Generators/EntityGenerator.php +++ b/src/Generators/EntityGenerator.php @@ -330,12 +330,12 @@ protected function checkResourceExists(string $path, string $resourceName, ?stri } } - protected function checkResourceNotExists(string $path, string $entity, string $resourceName, ?string $subFolder = null): void + protected function checkResourceNotExists(string $path, string $createableResource, string $requiredResource, ?string $subFolder = null): void { - if (!$this->classExists($path, $resourceName, $subFolder)) { - $filePath = $this->getClassPath($path, $resourceName, $subFolder); + if (!$this->classExists($path, $requiredResource, $subFolder)) { + $filePath = $this->getClassPath($path, $requiredResource, $subFolder); - throw new ResourceNotExistsException($entity, $filePath); + throw new ResourceNotExistsException($createableResource, $filePath); } } diff --git a/src/Generators/NovaResourceGenerator.php b/src/Generators/NovaResourceGenerator.php index 02c10a39..e48cd897 100644 --- a/src/Generators/NovaResourceGenerator.php +++ b/src/Generators/NovaResourceGenerator.php @@ -7,8 +7,6 @@ use Illuminate\Support\Facades\DB; use Laravel\Nova\NovaServiceProvider; use RonasIT\Support\Events\SuccessCreateMessage; -use RonasIT\Support\Exceptions\ClassNotExistsException; -use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; use RonasIT\Support\Support\CommandLineNovaField; use RonasIT\Support\Support\DatabaseNovaField;