Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Replace all occurrences of the search string with the replacement string
<?php str_replace( array|string $search, array|string $replace, string|array $subject, int &$count = null): string|array
<?php ->replaceFirst('App\\Models\\', '')
->replaceFirst('App\\', '');
return database_path('factories/' . str_replace('\\', '/', $subDirectory) . 'Factory.php');
}
<?php public function buildRelationFunction(string $column, $relationMethod = null)
{
$relationName = optional($relationMethod)->getName() ?? Str::camel(str_replace('_id', '', $column));
$foreignCallback = '\\App\\REPLACE_THIS::factory()';
try {
<?php try {
$relatedModel = get_class($this->modelInstance->$relationName()->getRelated());
return str_replace('App\\REPLACE_THIS', $relatedModel, $foreignCallback);
} catch (\Exception $e) {
return $foreignCallback;
}
<?php return $name;
}
$name = str_replace('/', '\\', $name);
return $this->qualifyClass(
trim($rootNamespace, '\\') . '\\' . $name
<?php $factoryQualifiedName = \Illuminate\Database\Eloquent\Factories\Factory::resolveFactoryName($modelClass);
$factoryNamespace = Str::beforeLast($factoryQualifiedName, '\\');
$contents = File::get(__DIR__ . '/../stubs/factory.stub');
$contents = str_replace('{{ factoryNamespace }}', $factoryNamespace, $contents);
$contents = str_replace('{{ namespacedModel }}', $modelClass, $contents);
$contents = str_replace('{{ model }}', class_basename($modelClass), $contents);
$contents = str_replace(' //', trim($definition, PHP_EOL), $contents);
<?php $factoryNamespace = Str::beforeLast($factoryQualifiedName, '\\');
$contents = File::get(__DIR__ . '/../stubs/factory.stub');
$contents = str_replace('{{ factoryNamespace }}', $factoryNamespace, $contents);
$contents = str_replace('{{ namespacedModel }}', $modelClass, $contents);
$contents = str_replace('{{ model }}', class_basename($modelClass), $contents);
$contents = str_replace(' //', trim($definition, PHP_EOL), $contents);
<?php $contents = File::get(__DIR__ . '/../stubs/factory.stub');
$contents = str_replace('{{ factoryNamespace }}', $factoryNamespace, $contents);
$contents = str_replace('{{ namespacedModel }}', $modelClass, $contents);
$contents = str_replace('{{ model }}', class_basename($modelClass), $contents);
$contents = str_replace(' //', trim($definition, PHP_EOL), $contents);
File::put($path, $contents);
<?php $contents = str_replace('{{ factoryNamespace }}', $factoryNamespace, $contents);
$contents = str_replace('{{ namespacedModel }}', $modelClass, $contents);
$contents = str_replace('{{ model }}', class_basename($modelClass), $contents);
$contents = str_replace(' //', trim($definition, PHP_EOL), $contents);
File::put($path, $contents);
}
<?php protected function loadModels(string $directory, array $models = []): Collection
{
if (!empty($models)) {
$dir = str_replace(app_path(), '', $directory);
return collect($models)->map(function ($name) use ($dir) {
if (strpos($name, '\\') !== false) {
<?php return $name;
}
return str_replace(
[DIRECTORY_SEPARATOR, basename($this->laravel->path()) . '\\'],
['\\', $this->laravel->getNamespace()],
basename($this->laravel->path()) . $dir . DIRECTORY_SEPARATOR . $name
);
});
}