Skip to content

Commit 2159ea0

Browse files
committed
feat: Refactor character and guild routes to support slug-based identification and update related views
1 parent 46c846a commit 2159ea0

28 files changed

Lines changed: 94 additions & 44 deletions

app/Http/Controllers/RankingController.php

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,33 @@ class RankingController extends Controller
1212
private const EQUIPMENT_MIN_SLOTS = 0;
1313
private const EQUIPMENT_NOT_SLOTS = [8];
1414

15-
public function showCharacter(int $id)
15+
public function showCharacter(string $idOrSlug)
1616
{
1717
/** @var AbstractChar $charModel */
1818
$charModel = app(AbstractChar::class);
1919

20-
$character = $charModel::query()
21-
->where('CharID', $id)
22-
->where('deleted', 0)
23-
->firstOrFail();
20+
$character = null;
21+
22+
if (ctype_digit($idOrSlug)) {
23+
$character = $charModel::query()
24+
->where('CharID', $idOrSlug)
25+
->where('deleted', 0)
26+
->first();
27+
}
28+
29+
if (!$character) {
30+
$charId = $charModel::query()
31+
->where('deleted', 0)
32+
->get(['CharID', 'CharName16'])
33+
->first(fn (AbstractChar $char) => $char->slug === $idOrSlug)
34+
?->CharID;
35+
36+
$character = $charId
37+
? $charModel::query()->where('CharID', $charId)->where('deleted', 0)->first()
38+
: null;
39+
}
40+
41+
abort_unless($character, 404);
2442

2543
$character->load('guild');
2644

@@ -43,11 +61,24 @@ public function showCharacter(int $id)
4361
]);
4462
}
4563

46-
public function showGuild(int $id)
64+
public function showGuild(string $idOrSlug)
4765
{
48-
$guild = Guild::query()
49-
->where('ID', $id)
50-
->firstOrFail();
66+
$guild = null;
67+
68+
if (ctype_digit($idOrSlug)) {
69+
$guild = Guild::query()->where('ID', $idOrSlug)->first();
70+
}
71+
72+
if (!$guild) {
73+
$guildId = Guild::query()
74+
->get(['ID', 'Name'])
75+
->first(fn (Guild $g) => $g->slug === $idOrSlug)
76+
?->ID;
77+
78+
$guild = $guildId ? Guild::query()->where('ID', $guildId)->first() : null;
79+
}
80+
81+
abort_unless($guild, 404);
5182

5283
$members = $guild->guildMembers()
5384
->orderBy('JoinDate', 'asc')

composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/dashboard.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dar
180180
@else
181181
<div class="divide-y divide-gray-100 dark:divide-gray-700">
182182
@foreach ($characters as $char)
183-
<a href="{{ route('ranking.characters.show', $char->CharID) }}"
183+
<a href="{{ route('ranking.characters.show', $char->slug) }}"
184184
class="flex items-center gap-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-700/40 -mx-6 px-6 transition">
185185
<img src="{{ $char->avatar_url }}" alt="{{ $char->CharName16 }}"
186186
class="w-10 h-10 rounded-full object-cover bg-gray-100 dark:bg-gray-700"

resources/views/livewire/rankings/character-ranking.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ class="inline-flex items-center justify-center w-6 h-6 rounded-full text-xs font
5656
<td class="px-4 py-3 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">
5757
@php $value = $row->{$col['column']} ?? ''; @endphp
5858
@if ($col['column'] === 'CharName16')
59-
<a href="{{ route('ranking.characters.show', $row->CharID) }}"
59+
<a href="{{ route('ranking.characters.show', Str::slug($row->CharName16 ?? '') ?: $row->CharID) }}"
6060
class="font-medium text-indigo-600 dark:text-indigo-400 hover:underline">
6161
{{ e((string) $value) }}
6262
</a>
6363
@elseif ($col['column'] === 'GuildName' && !empty($row->GuildID))
64-
<a href="{{ route('ranking.guilds.show', $row->GuildID) }}"
64+
<a href="{{ route('ranking.guilds.show', Str::slug($row->GuildName ?? '') ?: $row->GuildID) }}"
6565
class="text-indigo-600 dark:text-indigo-400 hover:underline">
6666
{{ e((string) $value) }}
6767
</a>

resources/views/livewire/rankings/guild-ranking.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class="inline-flex items-center justify-center w-6 h-6 rounded-full text-xs font
5656
<td class="px-4 py-3 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">
5757
@php $value = $row->{$col['column']} ?? ''; @endphp
5858
@if ($col['column'] === 'Name')
59-
<a href="{{ route('ranking.guilds.show', $row->ID) }}"
59+
<a href="{{ route('ranking.guilds.show', Str::slug($row->Name ?? '') ?: $row->ID) }}"
6060
class="font-medium text-indigo-600 dark:text-indigo-400 hover:underline">
6161
{{ e((string) $value) }}
6262
</a>

resources/views/ranking/character-detail.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class="h-48 w-auto mx-auto object-contain mb-4" />
1919
{{ e($character->CharName16) }}
2020
</h1>
2121
@if ($character->guild && $character->guild->ID !== 0)
22-
<a href="{{ route('ranking.guilds.show', $character->guild->ID) }}"
22+
<a href="{{ route('ranking.guilds.show', $character->guild->slug) }}"
2323
class="inline-flex items-center gap-1 mt-2 text-sm text-indigo-600 dark:text-indigo-400 hover:underline">
2424
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2525
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"

resources/views/ranking/guild-detail.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class="px-4 py-3 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
8282
{{ $loop->iteration }}
8383
</td>
8484
<td class="px-4 py-3 whitespace-nowrap text-sm">
85-
<a href="{{ route('ranking.characters.show', $member->CharID) }}"
85+
<a href="{{ route('ranking.characters.show', $member->slug) }}"
8686
class="inline-flex items-center gap-1 font-medium text-indigo-600 dark:text-indigo-400 hover:underline">
8787
@if ((int) $member->MemberClass === 0)
8888
<svg class="w-4 h-4 text-amber-500" fill="currentColor"

resources/views/templates/aether-gate/livewire/rankings/character-ranking.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ class="ag-input w-full pl-9 pr-4 py-2 text-sm" />
3939
<td>
4040
@php $value = $row->{$col['column']} ?? ''; @endphp
4141
@if ($col['column'] === 'CharName16')
42-
<a href="{{ route('ranking.characters.show', $row->CharID) }}"
42+
<a href="{{ route('ranking.characters.show', Str::slug($row->CharName16 ?? '') ?: $row->CharID) }}"
4343
class="font-semibold ag-text-surface hover:ag-text-primary transition-colors">
4444
{{ e((string) $value) }}
4545
</a>
4646
@elseif ($col['column'] === 'GuildName' && !empty($row->GuildID))
47-
<a href="{{ route('ranking.guilds.show', $row->GuildID) }}"
47+
<a href="{{ route('ranking.guilds.show', Str::slug($row->GuildName ?? '') ?: $row->GuildID) }}"
4848
class="ag-text-muted hover:ag-text-primary transition-colors">
4949
{{ e((string) $value) }}
5050
</a>

resources/views/templates/aether-gate/livewire/rankings/guild-ranking.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class="ag-input w-full pl-9 pr-4 py-2 text-sm" />
3838
<td>
3939
@php $value = $row->{$col['column']} ?? ''; @endphp
4040
@if ($col['column'] === 'Name')
41-
<a href="{{ route('ranking.guilds.show', $row->ID) }}"
41+
<a href="{{ route('ranking.guilds.show', Str::slug($row->Name ?? '') ?: $row->ID) }}"
4242
class="font-semibold ag-text-surface hover:ag-text-primary transition-colors">
4343
{{ e((string) $value) }}
4444
</a>

resources/views/templates/aether-gate/ranking/character-detail.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class="text-xs ag-text-muted ag-font-display uppercase tracking-widest">{{ __('r
190190
@if ($character->guild && $character->guild->ID !== 0)
191191
<div class="h-4 w-px" style="background: var(--ag-outline);"></div>
192192
{{-- Guild --}}
193-
<a href="{{ route('ranking.guilds.show', $character->guild->ID) }}"
193+
<a href="{{ route('ranking.guilds.show', $character->guild->slug) }}"
194194
class="flex items-center gap-2 hover:opacity-80 transition-opacity">
195195
<svg class="w-4 h-4 ag-text-muted" fill="none" stroke="currentColor" viewBox="0 0 24 24">
196196
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"

0 commit comments

Comments
 (0)