You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB

<?php
namespace Luthfi\CrudGenerator\Generators;
/**
* Model Factory Generator Class
*/
class ModelFactoryGenerator extends BaseGenerator
{
/**
* {@inheritDoc}
*/
public function generate(string $type = 'full')
{
$modelFactoryPath = $this->makeDirectory(database_path('factories'));
$modelFactoryClassPath = $modelFactoryPath.'/'.$this->modelNames['model_name'].'Factory.php';
if ($this->files->exists($modelFactoryClassPath)) {
$this->command->warn('Use the existing '.$this->modelNames['model_name'].' model factory.');
return;
}
$this->generateFile(
$modelFactoryClassPath,
$this->getContent('database/factories/model-factory')
);
$this->command->info($this->modelNames['model_name'].' model factory generated.');
}
/**
* {@inheritDoc}
*/
public function getContent(string $stubName)
{
$modelFactoryFileContent = $this->getStubFileContent($stubName);
$userModel = config('auth.providers.users.model');
if ('App\User' !== $userModel) {
$modelFactoryFileContent = str_replace('App\User', $userModel, $modelFactoryFileContent);
}
return $this->replaceStubString($modelFactoryFileContent);
}
}