2020-11-14 16:57:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Song;
|
2024-01-09 18:34:40 +00:00
|
|
|
use App\Models\User;
|
2020-11-14 16:57:25 +00:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
|
|
|
|
class SongFactory extends Factory
|
|
|
|
{
|
|
|
|
protected $model = Song::class;
|
|
|
|
|
2020-12-22 20:11:22 +00:00
|
|
|
/** @return array<mixed> */
|
2020-11-14 16:57:25 +00:00
|
|
|
public function definition(): array
|
|
|
|
{
|
|
|
|
return [
|
2024-01-10 23:11:45 +00:00
|
|
|
'album_id' => Album::factory(),
|
|
|
|
'artist_id' => static fn (array $attributes) => Album::find($attributes['album_id'])->artist_id,
|
2021-07-26 21:21:36 +00:00
|
|
|
'title' => $this->faker->sentence,
|
2020-11-14 16:57:25 +00:00
|
|
|
'length' => $this->faker->randomFloat(2, 10, 500),
|
|
|
|
'track' => random_int(1, 20),
|
2022-09-23 06:21:29 +00:00
|
|
|
'disc' => random_int(1, 5),
|
2020-11-14 16:57:25 +00:00
|
|
|
'lyrics' => $this->faker->paragraph(),
|
2020-12-22 20:11:22 +00:00
|
|
|
'path' => '/tmp/' . uniqid() . '.mp3',
|
2022-09-23 06:21:29 +00:00
|
|
|
'genre' => $this->faker->randomElement(['Rock', 'Pop', 'Jazz', 'Classical', 'Metal', 'Hip Hop', 'Rap']),
|
|
|
|
'year' => $this->faker->year(),
|
2024-01-09 18:34:40 +00:00
|
|
|
'is_public' => $this->faker->boolean(),
|
|
|
|
'owner_id' => User::factory(),
|
2020-11-14 16:57:25 +00:00
|
|
|
'mtime' => time(),
|
|
|
|
];
|
|
|
|
}
|
2024-01-09 18:34:40 +00:00
|
|
|
|
|
|
|
public function public(): self
|
|
|
|
{
|
|
|
|
return $this->state(fn () => ['is_public' => true]); // @phpcs:ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
public function private(): self
|
|
|
|
{
|
|
|
|
return $this->state(fn () => ['is_public' => false]); // @phpcs:ignore
|
|
|
|
}
|
2020-11-14 16:57:25 +00:00
|
|
|
}
|