From: Daniel Karbach Date: Thu, 10 Jul 2025 13:09:07 +0000 (+0200) Subject: tournament names X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=e758b245cfee1c4fb0430f2b41b29fdedce3e589;p=alttp.git tournament names --- diff --git a/app/Http/Controllers/SitemapXmlController.php b/app/Http/Controllers/SitemapXmlController.php index a99108b..6d9f8d7 100644 --- a/app/Http/Controllers/SitemapXmlController.php +++ b/app/Http/Controllers/SitemapXmlController.php @@ -19,7 +19,11 @@ class SitemapXmlController extends Controller foreach (Tournament::all() as $tournament) { $url = new SitemapUrl(); - $url->path = '/tournaments/'.$tournament->id; + if ($tournament->name) { + $url->path = '/tournaments/'.$tournament->name; + } else { + $url->path = '/tournaments/'.$tournament->id; + } $url->lastmod = $tournament->updated_at ? $tournament->updated_at : ($tournament->created_at ? $tournament->created_at : now()); $url->changefreq = $tournament->locked ? 'never' : 'daily'; $url->priority = $tournament->locked ? 0.5 : 1.0; diff --git a/app/Http/Controllers/TournamentController.php b/app/Http/Controllers/TournamentController.php index 12289a2..a8fa952 100644 --- a/app/Http/Controllers/TournamentController.php +++ b/app/Http/Controllers/TournamentController.php @@ -25,15 +25,15 @@ class TournamentController extends Controller return $tournament->toJson(); } - public function single(Request $request, $id) { - $tournament = Tournament::with( + public function single(Request $request, Tournament $tournament) { + $this->authorize('view', $tournament); + $tournament->load([ 'applications', 'applications.user', 'description', 'participants', 'participants.user', - )->findOrFail($id); - $this->authorize('view', $tournament); + ]); $rounds = $tournament->rounds()->with(['results', 'results.user'])->limit(25)->get(); foreach ($rounds as $round) { if (!Gate::allows('seeResults', $round)) { @@ -156,4 +156,11 @@ class TournamentController extends Controller return $tournament->toJson(); } + public function web(Request $request, Tournament $tournament) { + $view = view('app') + ->with('title', $tournament->getTranslatedTitle()) + ->with('description', $tournament->getTranslatedShort()); + return $view; + } + } diff --git a/app/Models/Tournament.php b/app/Models/Tournament.php index 44bcaf0..8080d2a 100644 --- a/app/Models/Tournament.php +++ b/app/Models/Tournament.php @@ -5,10 +5,17 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Tournament extends Model -{ +class Tournament extends Model { + use HasFactory; + public function resolveRouteBinding(mixed $value, $field = null): Tournament|null { + if (is_null($field) && !is_numeric($value)) { + return $this->where('name', '=', $value)->firstOrFail(); + } + return parent::resolveRouteBinding($value, $field); + } + public function getRunners() { $runners = []; @@ -83,6 +90,20 @@ class Tournament extends Model return $this->hasMany(Round::class)->orderBy('number', 'DESC'); } + public function getTranslatedTitle(): string { + if ($this->description) { + return $this->description->getTranslatedProperty('title'); + } + return $this->title; + } + + public function getTranslatedShort(): string { + if ($this->description) { + return $this->description->getTranslatedProperty('short'); + } + return ''; + } + protected $casts = [ 'accept_applications' => 'boolean', diff --git a/database/migrations/2025_07_10_123521_tournament_names.php b/database/migrations/2025_07_10_123521_tournament_names.php new file mode 100644 index 0000000..5f67338 --- /dev/null +++ b/database/migrations/2025_07_10_123521_tournament_names.php @@ -0,0 +1,26 @@ +string('name')->nullable()->default(null)->after('id')->unique(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void { + Schema::table('tournaments', function (Blueprint $table) { + $table->dropColumn('name'); + }); + } +}; diff --git a/resources/js/pages/Tournament.jsx b/resources/js/pages/Tournament.jsx index 661eaa7..8f353c1 100644 --- a/resources/js/pages/Tournament.jsx +++ b/resources/js/pages/Tournament.jsx @@ -205,7 +205,7 @@ export const Component = () => { content={getTranslation(tournament.description, 'short', i18n.language)} /> : null} - + call('App\Http\Controllers\TechniqueController@web', ['type' => 'tech', 'name' => $name]); }); +Route::get('/tournaments/{tournament}', 'App\Http\Controllers\TournamentController@web'); + Route::get('/twitch/guessing-game-leaderboard/{channel:twitch_id}/{type}', 'App\Http\Controllers\ChannelController@getGuessingGameLeaderboard'); Route::view('/{path?}', 'app')->where('path', '.*');