Skip to content

Commit

Permalink
fix bugs with factory creation
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 9, 2020
1 parent 13751a1 commit c7186e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ protected function buildClass($name)

$model = class_basename($namespaceModel);

if (Str::startsWith($namespaceModel, 'App\\Models')) {
$namespace = Str::beforeLast('Database\\Factories\\'.Str::after($namespaceModel, 'App\\Models\\'), '\\');
} else {
$namespace = 'Database\\Factories';
}

$replace = [
'{{ factoryNamespace }}' => $namespace,
'NamespacedDummyModel' => $namespaceModel,
'{{ namespacedModel }}' => $namespaceModel,
'{{namespacedModel}}' => $namespaceModel,
Expand All @@ -88,13 +95,11 @@ protected function buildClass($name)
*/
protected function getPath($name)
{
$name = str_replace(
['\\', '/'], '', $this->argument('name')
);
$name = Str::replaceFirst('App\\', '', $name);

$name = Str::finish($name, 'Factory');
$name = Str::finish($this->argument('name'), 'Factory');

return $this->laravel->databasePath()."/factories/{$name}.php";
return $this->laravel->databasePath().'/factories/'.str_replace('\\', '/', $name).'.php';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Database\Factories;
namespace {{ factoryNamespace }};

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle()
*/
protected function createFactory()
{
$factory = Str::studly(class_basename($this->argument('name')));
$factory = Str::studly($this->argument('name'));

$this->call('make:factory', [
'name' => "{$factory}Factory",
Expand Down

0 comments on commit c7186e0

Please sign in to comment.