63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Character;
|
|
use App\Models\Raid;
|
|
use App\Models\Wow;
|
|
use App\Models\Card as Model;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class CardFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Model::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function definition()
|
|
{
|
|
$words = $this->faker->words(10);
|
|
$words[rand(0, count($words)-1)] = '?';
|
|
|
|
return [
|
|
'raid_id' => null,
|
|
'character_id' => null,
|
|
'body' => join(" ", $words)
|
|
];
|
|
}
|
|
|
|
public function random_character()
|
|
{
|
|
return $this->state(function (array $attributes) {
|
|
return [
|
|
'raid_id' => Character::all()->random()->id,
|
|
];
|
|
});
|
|
}
|
|
|
|
public function random_class()
|
|
{
|
|
return $this->state(function (array $attributes) {
|
|
return [
|
|
'class' => $this->faker->randomElement(array_keys(Wow::$classes)),
|
|
];
|
|
});
|
|
}
|
|
|
|
public function random_raid()
|
|
{
|
|
return $this->state(function (array $attributes) {
|
|
return [
|
|
'raid_id' => Raid::factory(),
|
|
];
|
|
});
|
|
}
|
|
}
|