+ Game, GamePuzzle Model & Factory
This commit is contained in:
parent
c08dc63b8f
commit
2f3c01f5f9
11
picquiz/app/Models/Game.php
Normal file
11
picquiz/app/Models/Game.php
Normal 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;
|
||||
}
|
11
picquiz/app/Models/GamePuzzle.php
Normal file
11
picquiz/app/Models/GamePuzzle.php
Normal 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;
|
||||
}
|
30
picquiz/database/factories/GameFactory.php
Normal file
30
picquiz/database/factories/GameFactory.php
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
31
picquiz/database/factories/GamePuzzleFactory.php
Normal file
31
picquiz/database/factories/GamePuzzleFactory.php
Normal 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,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user