initial commit
This commit is contained in:
commit
1e1aa7d461
215 changed files with 35140 additions and 0 deletions
47
database/factories/CharacterFactory.php
Normal file
47
database/factories/CharacterFactory.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Character;
|
||||
use App\Models\CharacterProfession;
|
||||
use App\Warcraft\Classes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class CharacterFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Character::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'name' => $this->faker->unique()->firstName(),
|
||||
'race' => $this->faker->randomElement(['human', 'dwarf', 'gnome', 'night elf', 'draenei', 'orc', 'troll', 'tauren', 'undead', 'blood elf']),
|
||||
'gender' => $this->faker->randomElement(['F', 'M']),
|
||||
'class' => function (array $attributes) {
|
||||
return (new Classes)->race($attributes['race'])->random();
|
||||
},
|
||||
'level' => $this->faker->numberBetween(1, 70),
|
||||
];
|
||||
}
|
||||
|
||||
public function hasRandomExistingProfessions($count)
|
||||
{
|
||||
$professions = CharacterProfession::factory()
|
||||
->count($count);
|
||||
|
||||
return $this->has($professions, 'professions');
|
||||
}
|
||||
}
|
||||
49
database/factories/CharacterProfessionFactory.php
Normal file
49
database/factories/CharacterProfessionFactory.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\CharacterProfession;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
use App\Models\Character;
|
||||
use App\Models\Profession;
|
||||
|
||||
class CharacterProfessionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = CharacterProfession::class;
|
||||
|
||||
/**
|
||||
* Array to keep track uf used id's to make
|
||||
* sure we generate unique ones.
|
||||
*/
|
||||
protected static $ids = [];
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'character_id' => Character::factory(),
|
||||
'profession_id' => function (array $attributes) {
|
||||
// Abit of a hack to make sure we generate
|
||||
// unique character_id,profession_id pairs.
|
||||
$ch_id = $attributes['character_id'];
|
||||
if (!isset(self::$ids[$ch_id])) {
|
||||
self::$ids[$ch_id] = [];
|
||||
}
|
||||
|
||||
$id = self::$ids[$ch_id][] = Profession::whereNotIn('id', self::$ids[$ch_id])->get()->random()->id;
|
||||
return $id;
|
||||
},
|
||||
'skill' => $this->faker->numberBetween(1, 375),
|
||||
];
|
||||
}
|
||||
}
|
||||
36
database/factories/ItemFactory.php
Normal file
36
database/factories/ItemFactory.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Item;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ItemFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Item::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'external_id' => $this->faker->unique()->randomNumber(),
|
||||
'name' => $this->faker->unique()->sentence(8),
|
||||
'slug' => function (array $attributes) {
|
||||
return Str::slug($attributes['name']);
|
||||
},
|
||||
'texture' => $this->faker->numberBetween(1, 999999),
|
||||
'color' => Str::of($this->faker->hexcolor)->replace('#', '')
|
||||
];
|
||||
}
|
||||
}
|
||||
30
database/factories/ProfessionFactory.php
Normal file
30
database/factories/ProfessionFactory.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Profession;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ProfessionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Profession::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->word,
|
||||
];
|
||||
}
|
||||
}
|
||||
29
database/factories/RecipeCategoryFactory.php
Normal file
29
database/factories/RecipeCategoryFactory.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\RecipeCategory;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class RecipeCategoryFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = RecipeCategory::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->sentence(3)
|
||||
];
|
||||
}
|
||||
}
|
||||
66
database/factories/RecipeFactory.php
Normal file
66
database/factories/RecipeFactory.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Profession;
|
||||
use App\Models\Item;
|
||||
use App\Models\Recipe;
|
||||
use App\Models\RecipeCategory;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class RecipeFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Recipe::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'profession_id' => Profession::factory(),
|
||||
'category_id' => RecipeCategory::factory(),
|
||||
'item_id' => Item::factory(),
|
||||
//'slug' => function (array $attributes) {
|
||||
// return Str::slug(Item::find($attributes['item_id'])->name);
|
||||
//}
|
||||
];
|
||||
}
|
||||
|
||||
public function randomExistingProfession()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'profession_id' => Profession::all()->random()->id,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function randomExistingCategory()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'category_id' => RecipeCategory::all()->random()->id,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function randomExistingItem()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
$ids = Recipe::select('item_id')->orderBy('item_id')->get()->pluck('item_id');
|
||||
return [
|
||||
'item_id' => Item::whereNotIn('id', $ids)->get()->random()->id,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
32
database/factories/UserFactory.php
Normal file
32
database/factories/UserFactory.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = User::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'username' => $this->faker->username(),
|
||||
'role' => $this->faker->randomElement(['user', 'admin']),
|
||||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue