Skip to content

Commit 93d8983

Browse files
used backed enum for version
1 parent 3632b4a commit 93d8983

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

app/Enums/Version.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum Version: string
6+
{
7+
case FOUR_X = '4.x';
8+
case THREE_X = '3.x';
9+
case TWO_X = '2.x';
10+
case ONE_X = '1.x';
11+
12+
public static function latest(): self
13+
{
14+
return self::FOUR_X;
15+
}
16+
}

app/Support/Version.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

routes/web.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3+
use App\Enums\Version;
34
use App\Http\Controllers;
45
use App\Models\Article;
56
use App\Models\Plugin;
67
use App\Models\Star;
78
use Illuminate\Http\RedirectResponse;
89
use Illuminate\Support\Facades\Route;
910
use Illuminate\Support\Str;
10-
use App\Support\Version;
1111

1212
/*
1313
|--------------------------------------------------------------------------
@@ -55,9 +55,10 @@
5555

5656
Route::redirect('/discord', 'https://discord.gg/filament')->name('discord');
5757

58-
Route::get('/api/{version?}', function (string $version = Version::LATEST): RedirectResponse {
59-
return redirect('/api/' . $version . '/index.html');
60-
})->where('version', '[1-'.Str::before(Version::LATEST, '.x').']+\.x')->name('api-docs');
58+
Route::get('/api/{version?}', function (Version $version = null): RedirectResponse {
59+
$version = $version ?? Version::latest();
60+
return redirect('/api/' . $version->value . '/index.html');
61+
})->name('api-docs');
6162

6263
Route::prefix('/docs')->group(function () {
6364
Route::get('/{slug?}', function (string $slug = null): string | RedirectResponse {
@@ -75,7 +76,7 @@
7576
$slug = trim($slug, '/');
7677

7778
if (filled($slug) && (! str_contains($slug, '.x'))) {
78-
return redirect()->route('docs', ['slug' => Version::LATEST."/{$slug}"]);
79+
return redirect()->route('docs', ['slug' => Version::latest()->value."/{$slug}"]);
7980
}
8081

8182
$filePath = base_path("docs/preserved-dist/{$slug}/index.html");

0 commit comments

Comments
 (0)