From 2258f864983dd57d3872463f2aa4eead79cd66d1 Mon Sep 17 00:00:00 2001 From: levchenko-ivan Date: Sun, 26 May 2024 18:03:38 +0300 Subject: [PATCH] fix: filename --- src/Commands/LaravelCodeBuildCommand.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Commands/LaravelCodeBuildCommand.php b/src/Commands/LaravelCodeBuildCommand.php index 7a2483d..732c3d2 100644 --- a/src/Commands/LaravelCodeBuildCommand.php +++ b/src/Commands/LaravelCodeBuildCommand.php @@ -161,10 +161,8 @@ protected function buildCode(CodeStructure $codeStructure, CodePathContract $cod } $buildFactory->call($builder->value(), $this->stubDir . $builder->stub()); - - $codePathItem = $codePath->path($builder->value()); - $filePath = substr($codePathItem->file(), strpos($codePathItem->file(), '/app') + 1); - $this->info($filePath . ' was created successfully!'); + $filePath = $codePath->path($builder->value())->file(); + $this->info($this->projectFileName($filePath) . ' was created successfully!'); } } @@ -227,7 +225,8 @@ protected function prepareGeneration(string $generationPath, CodeStructure $code if(! $isGenerationDir) { foreach ($this->builders as $buildType) { if($fileSystem->isFile($codePath->path($buildType->value())->file())) { - $this->replaceCautions[$buildType->value()] = $buildType->stub() . " already exists, are you sure you want to replace it?"; + $this->replaceCautions[$buildType->value()] = + $this->projectFileName($codePath->path($buildType->value())->file()) . " already exists, are you sure you want to replace it?"; } } } @@ -265,4 +264,17 @@ protected function builders(): array BuildType::TABLE, ]; } + + protected function projectFileName(string $filePath): string + { + if(str_contains($filePath, '/resources/views')) { + return substr($filePath, strpos($filePath, '/resources/views') + 1); + } + + if(str_contains($filePath, '/routes')) { + return substr($filePath, strpos($filePath, '/routes') + 1); + } + + return substr($filePath, strpos($filePath, '/app') + 1); + } }