composed project, added packages, models, controllers, seeders, mirgations etc.
This commit is contained in:
56
database/factories/EventFactory.php
Normal file
56
database/factories/EventFactory.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Services\Faker\Image\{Contracts\ProviderInterface, FakerImageProvider, ImageStorage};
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
use Random\RandomException;
|
||||
|
||||
/**
|
||||
* @extends Factory<Event>
|
||||
*/
|
||||
class EventFactory extends Factory
|
||||
{
|
||||
private const int NB_WORDS = 5;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
static $venuesCount = config('common.seeding.model.venue.count');
|
||||
static $counter = 1;
|
||||
static $imageProvider = app(FakerImageProvider::class)->use(config('image.faker.provider.loremflickr.type'))
|
||||
->apply();
|
||||
|
||||
$image = new ImageStorage(
|
||||
config('image.storage.poster'),
|
||||
random_int(400, 1280),
|
||||
random_int(400, 960),
|
||||
ProviderInterface::KEYWORDS
|
||||
);
|
||||
|
||||
$poster = $imageProvider->getImage($image);
|
||||
|
||||
// Note: numberBetween method is unsafe if you need all `venues`.`id` values be used for constraining ¯\_(ツ)_/¯
|
||||
$venuesId = $counter > $venuesCount ? $this->faker->numberBetween(1, $venuesCount) : $counter++;
|
||||
|
||||
return [
|
||||
'venue_id' => $venuesId,
|
||||
'name' => Str::of($this->faker->sentence(self::NB_WORDS))->rtrim('.'),
|
||||
'event_date' => $this->faker->unique()->dateTimeBetween(
|
||||
'-3 months',
|
||||
'3 months',
|
||||
env('APP_TIMEZONE', 'UTC')
|
||||
),
|
||||
'poster' => $poster,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user