Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Checks if a value exists in an array
<?php in_array(mixed $needle, array $haystack, bool $strict = false): bool
<?php public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (!in_array($value, $this->values)) {
throw new \InvalidArgumentException("Invalid '" . $this->getName() . "' value.");
}
return $value;
<?php foreach ($controller->methods() as $name => $statements) {
$method = str_replace('{{ method }}', $name, $template);
if (in_array($name, ['edit', 'update', 'show', 'destroy'])) {
$context = Str::singular($controller->prefix());
$reference = $this->fullyQualifyModelReference($controller->namespace(), Str::camel($context));
$variable = '$' . Str::camel($context);
<?php foreach ($fillable as $column) {
if (in_array($column->name(), ['id', 'softdeletes', 'softdeletestz'])) {
continue;
}
<?php $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());
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => ";
$definition .= '$this->faker->' . $faker;
<?php json_encode($column->attributes()),
$definition
);
} elseif (in_array($column->dataType(), ['decimal', 'double', 'float'])) {
$faker = FakerRegistry::fakerData($column->name()) ?? FakerRegistry::fakerDataType($column->dataType());
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => ";
$definition .= '$this->faker->' . $faker;
<?php implode(', ', [$scale, 0, (str_repeat(9, $precision - $scale) . '.' . str_repeat(9, $scale))]),
$definition
);
} elseif (in_array($column->dataType(), ['json', 'jsonb'])) {
$default = $column->defaultValue() ?? '{}';
$definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => '{$default}'," . PHP_EOL;
} elseif ($column->dataType() === 'morphs') {
<?php $nonNullableColumns = array_filter(
$columns,
fn (Column $column) => !in_array('nullable', $column->modifiers())
);
return array_filter(
<?php $dataType = 'unsignedBigInteger';
}
if (in_array($dataType, self::UNSIGNABLE_TYPES) && in_array('unsigned', $column->modifiers())) {
$dataType = 'unsigned' . ucfirst($dataType);
}
<?php $dataType = 'unsigned' . ucfirst($dataType);
}
if (in_array($dataType, self::NULLABLE_TYPES) && $column->isNullable()) {
$dataType = 'nullable' . ucfirst($dataType);
}
<?php if (!empty($column->attributes()) && !$this->isIdOrUuid($column->dataType())) {
$column_definition .= ', ';
if (in_array($column->dataType(), ['set', 'enum'])) {
$column_definition .= json_encode($column->attributes());
} else {
$column_definition .= implode(', ', $column->attributes());
<?php $method = 'foreignId';
}
$prefix = in_array('nullable', $modifiers)
? '$table->' . "{$method}('{$column_name}')->nullable()"
: '$table->' . "{$method}('{$column_name}')";
<?php protected function isIdOrUuid(string $dataType)
{
return in_array($dataType, ['id', 'uuid']);
}
}
<?php $phpDoc .= PHP_EOL;
$phpDoc .= ' * @property string|null $' . $column->name() . '_type';
$phpDoc .= PHP_EOL;
} elseif (in_array($column->dataType(), ['softDeletesTz', 'softDeletes'])) {
$phpDoc .= ' * @property \Carbon\Carbon $deleted_at';
$phpDoc .= PHP_EOL;
} else {
<?php if ($type === 'morphTo') {
$relationship = sprintf('$this->%s()', $type);
} elseif (in_array($type, ['morphMany', 'morphOne', 'morphToMany'])) {
$relation = Str::lower($is_model_fqn ? Str::singular(Str::afterLast($column_name, '\\')) : Str::singular($column_name)) . 'able';
$relationship = sprintf('$this->%s(%s::class, \'%s\')', $type, $fqcn, $relation);
} elseif ($type === 'morphedByMany') {
<?php if ($type === 'morphTo') {
$method_name = Str::lower($class_name);
} elseif (in_array($type, ['hasMany', 'belongsToMany', 'morphMany', 'morphToMany', 'morphedByMany'])) {
$method_name = Str::plural($is_model_fqn ? Str::afterLast($column_name, '\\') : $column_name);
}