forge/database/factories/SptVersionFactory.php

39 lines
1.1 KiB
PHP
Raw Normal View History

2024-05-15 00:31:24 -04:00
<?php
namespace Database\Factories;
use App\Models\SptVersion;
use App\Support\Version;
2024-05-15 00:31:24 -04:00
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
2024-09-11 23:08:58 -04:00
/**
* @extends Factory<SptVersion>
*/
2024-05-15 00:31:24 -04:00
class SptVersionFactory extends Factory
{
protected $model = SptVersion::class;
public function definition(): array
{
$versionString = $this->faker->numerify('#.#.#');
try {
$version = new Version($versionString);
} catch (\Exception $e) {
$version = new Version('0.0.0');
}
2024-05-15 00:31:24 -04:00
return [
'version' => $versionString,
'version_major' => $version->getMajor(),
'version_minor' => $version->getMinor(),
'version_patch' => $version->getPatch(),
'version_pre_release' => $version->getPreRelease(),
'color_class' => $this->faker->randomElement(['red', 'green', 'emerald', 'lime', 'yellow', 'grey']),
'link' => $this->faker->url,
2024-05-15 00:31:24 -04:00
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
];
}
}