Skip to content

Commit

Permalink
fix namespace of factory
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed May 30, 2024
1 parent 6a740e3 commit 7eadfd7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/Commands/Modules/MakeCrudModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,27 +313,13 @@ private function makeSeeder(string $name)
*/
private function makeFactory(string $name)
{
$filename = $name.'Factory';
$factoryPath = config('laravel-crod.modules.factory_path', 'Database\Factories');
$correctPath = LaravelCrodServiceFacade::changeBackSlashToSlash($factoryPath);

$this->callSilent('make:factory', [
'name' => $filename,
]);

try {
$filenameWithExt = "$filename.php";
$concurrentDirectory = base_path($this->module_name_space."/$name/$correctPath");

if (!mkdir($concurrentDirectory) && !is_dir($concurrentDirectory)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
rename(
database_path("factories/$filenameWithExt"),
base_path($this->module_name_space."/$name/$correctPath/$filenameWithExt")
);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
$this->makeStubFile(
base_path($this->module_name_space."\\$name\\$factoryPath"),
$name,
'Factory',
'/../Stubs/module/factory.stub'
);
}
}
18 changes: 18 additions & 0 deletions src/Stubs/module/factory.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace $NAMESPACE$;

use Illuminate\Database\Eloquent\Factories\Factory;

class $NAMESPACE$Factory extends Factory
{
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
//
];
}
}

0 comments on commit 7eadfd7

Please sign in to comment.