Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Return a formatted string
<?php sprintf(string $format, mixed ...$values): string
<?php return $raw_value;
}
return sprintf('"%s"', $raw_value);
},
$options
);
<?php protected function getPath(Model $model)
{
$path = str_replace('\\', '/', Blueprint::relativeNamespace($model->fullyQualifiedClassName()));
return sprintf('%s/%s.php', $this->basePath ?? Blueprint::appPath(), $path);
}
protected function create(string $path, $content)
<?php if ($key === 'id') {
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => ";
$definition .= sprintf('%s::factory()', $class);
$definition .= ',' . PHP_EOL;
} else {
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => ";
<?php $definition .= ',' . PHP_EOL;
} else {
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => ";
$definition .= sprintf('%s::factory()->create()->%s', $class, $key);
$definition .= ',' . PHP_EOL;
}
} elseif ($column->dataType() === 'id' || ($column->dataType() === 'uuid' && Str::endsWith($column->name(), '_id'))) {
<?php $this->addImport($model, $reference->fullyQualifiedNamespace() . '\\' . $class);
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => ";
$definition .= sprintf('%s::factory()', $class);
$definition .= ',' . PHP_EOL;
} elseif (in_array($column->dataType(), ['enum', 'set']) && !empty($column->attributes())) {
$faker = FakerRegistry::fakerData($column->name()) ?? FakerRegistry::fakerDataType($column->dataType());
<?php if ($column->isNullable()) {
continue;
}
$definition .= sprintf('%s%s => $this->faker->%s,%s', str_repeat(self::INDENT, 3), "'{$column->name()}_id'", FakerRegistry::fakerDataType('id'), PHP_EOL);
$definition .= sprintf('%s%s => $this->faker->%s,%s', str_repeat(self::INDENT, 3), "'{$column->name()}_type'", FakerRegistry::fakerDataType('string'), PHP_EOL);
} elseif ($column->dataType() === 'rememberToken') {
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => ";
<?php continue;
}
$definition .= sprintf('%s%s => $this->faker->%s,%s', str_repeat(self::INDENT, 3), "'{$column->name()}_id'", FakerRegistry::fakerDataType('id'), PHP_EOL);
$definition .= sprintf('%s%s => $this->faker->%s,%s', str_repeat(self::INDENT, 3), "'{$column->name()}_type'", FakerRegistry::fakerDataType('string'), PHP_EOL);
} elseif ($column->dataType() === 'rememberToken') {
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => ";
$definition .= 'Str::random(10)';
<?php }
if (($faker === 'word') && (!empty($column->attributes()))) {
$faker = sprintf("regexify('[A-Za-z0-9]{%s}')", current($column->attributes()));
}
$definition .= '$this->faker->' . $faker;
<?php $modifierKey = key($modifier);
$modifierValue = addslashes(current($modifier));
if ($modifierKey === 'default' && ($modifierValue === 'null' || $dataType === 'boolean' || $this->isNumericDefault($dataType, $modifierValue))) {
$column_definition .= sprintf('->%s(%s)', $modifierKey, $modifierValue);
} else {
$column_definition .= sprintf("->%s('%s')", $modifierKey, $modifierValue);
}
<?php if ($modifierKey === 'default' && ($modifierValue === 'null' || $dataType === 'boolean' || $this->isNumericDefault($dataType, $modifierValue))) {
$column_definition .= sprintf('->%s(%s)', $modifierKey, $modifierValue);
} else {
$column_definition .= sprintf("->%s('%s')", $modifierKey, $modifierValue);
}
} elseif ($modifier === 'unsigned' && Str::startsWith($dataType, 'unsigned')) {
continue;
<?php if (array_key_exists('morphTo', $relationships)) {
foreach ($relationships['morphTo'] as $morphTo) {
$definition .= self::INDENT . sprintf('$table->unsignedBigInteger(\'%s\');', Str::lower($morphTo . '_id')) . PHP_EOL;
$definition .= self::INDENT . sprintf('$table->string(\'%s\');', Str::lower($morphTo . '_type')) . PHP_EOL;
}
}
<?php if (array_key_exists('morphTo', $relationships)) {
foreach ($relationships['morphTo'] as $morphTo) {
$definition .= self::INDENT . sprintf('$table->unsignedBigInteger(\'%s\');', Str::lower($morphTo . '_id')) . PHP_EOL;
$definition .= self::INDENT . sprintf('$table->string(\'%s\');', Str::lower($morphTo . '_type')) . PHP_EOL;
}
}
<?php $definition .= self::INDENT . '$table->foreignId(\'' . $foreign . '\');' . PHP_EOL;
}
$definition .= self::INDENT . sprintf('$table->unsignedBigInteger(\'%s\');', Str::lower(Str::singular($parentTable) . 'able' . '_id')) . PHP_EOL;
$definition .= self::INDENT . sprintf('$table->string(\'%s\');', Str::lower(Str::singular($parentTable) . 'able' . '_type')) . PHP_EOL;
return trim($definition);
<?php }
$definition .= self::INDENT . sprintf('$table->unsignedBigInteger(\'%s\');', Str::lower(Str::singular($parentTable) . 'able' . '_id')) . PHP_EOL;
$definition .= self::INDENT . sprintf('$table->string(\'%s\');', Str::lower(Str::singular($parentTable) . 'able' . '_type')) . PHP_EOL;
return trim($definition);
}
<?php $phpDoc .= ' * @property \Carbon\Carbon $deleted_at';
$phpDoc .= PHP_EOL;
} else {
$phpDoc .= sprintf(' * @property %s $%s', $this->phpDataType($column->dataType()), $column->name());
$phpDoc .= PHP_EOL;
}
}