Skip to content

Commit

Permalink
feat: map pool map creation
Browse files Browse the repository at this point in the history
  • Loading branch information
stanrunge committed Nov 13, 2024
1 parent 2d388e5 commit 74a2391
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function show(string $id)
*/
public function edit(string $id)
{
return Inertia::render('MapPools/Edit', ['mapPool' => MapPool::find($id)]);
return Inertia::render('MapPools/Edit', ['mapPool' => MapPool::with('mapPoolMaps')->find($id)]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ public function store(Request $request)
{
$validated = $request->validate([
'map_pool_id' => 'required|exists:map_pools,id',
'mod_id' => 'required|exists:mods,id',
]);

$mapPool = MapPool::find($validated['map_pool_id']);

$mapPool->mapPoolMaps()->create([
'mod_id' => $validated['mod_id'],
]);
$mapPool->mapPoolMaps()->create();

return redirect()->route('map-pools.show', $mapPool);
return redirect()->route('map_pools.edit', $mapPool);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public function up(): void
$table->timestamps();
});

Schema::create('map_pool_maps', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(MapPool::class);
$table->timestamps();
});

Schema::create('vash_matches', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(MapPool::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,41 @@
let form = useForm({
map_pool_id: mapPool.id,
mod_id: null,
})
</script>

<Layout>
<h1>{mapPool.id}</h1>

<div class="flex flex-col justify-center text-center">
<table>
<form onsubmit={preventDefault(() => $form.post('/map_pool_maps'))}>
<button class="my-3 rounded bg-white px-4 py-2 text-black">Add Map</button>
</form>
<table class="table-auto">
<thead>
<tr>
<th>#</th>
<th>Mod</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{#each mapPool.maps as map, index (map.id)}
{#each mapPool.map_pool_maps as map, index (map.id)}
<tr>
<td>{index + 1}</td>
<td
><select name="" id="">
{#each mods as mod}
<option value={mod.id}>{mod.name}</option>
{/each}
</select></td
>
<td>{map.name}</td>
<td>{map.description}</td>
</tr>
{/each}
</tbody>
</table>
<form onsubmit={preventDefault(() => $form.post('/map_pool_mods'))}>
<button>Add Mod</button>
</form>
</div>
</Layout>

0 comments on commit 74a2391

Please sign in to comment.