+ Game, GamePuzzle Model & Factory

This commit is contained in:
anon 2022-11-03 07:35:40 +01:00
parent c08dc63b8f
commit 2f3c01f5f9
4 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Game extends Model
{
use HasFactory;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class GamePuzzle extends Model
{
use HasFactory;
}

View File

@ -0,0 +1,30 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\GamePuzzle;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Game>
*/
class GameFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
"player" => 1,
];
}
public function len($len){
return $this->state(function($l) use ($len) {
GamePuzzle::factory()->count($l)->create();
});
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\GamePuzzle>
*/
class GamePuzzleFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'puzzle' => $faker->randomNumber(DB::table('puzzles')->count(), false),
];
}
public function game($id){
return $this->state(function($i) use ($id) {
return [
"game" => $i,
];
});
}
}