Skip to content

Commit

Permalink
Определение текущей страницы по умолчанию (#253)
Browse files Browse the repository at this point in the history
* Update Docs.php

* Update DocsController.php

* Update web.php
  • Loading branch information
demn98 authored Nov 20, 2024
1 parent 364b96a commit 72b33a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/Docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

class Docs
{
/**
* Default document of Laravel documentation
*/
public const DEFAULT_DOCUMENT = 'installation';

/**
* Default version of Laravel documentation
*/
Expand Down Expand Up @@ -88,7 +93,7 @@ public function raw(): string
// Abort the request if the page doesn't exist
abort_if(
$raw === null,
redirect(status: 300)->route('docs', ['version' => $this->version, 'page' => 'installation'])
redirect(status: 300)->route('docs', ['version' => $this->version, 'page' => self::DEFAULT_DOCUMENT])
);

return $raw;
Expand Down
7 changes: 6 additions & 1 deletion app/Http/Controllers/DocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ class DocsController extends Controller
*
* @return \Illuminate\View\View|
*/
public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'installation')
public function show(string $version = Docs::DEFAULT_VERSION, string $page = null)
{
abort_if(
$page === null,
redirect(status: 300)->route('docs', ['version' => $version, 'page' => Docs::DEFAULT_DOCUMENT])
);

$docs = new Docs($version, $page);

return $docs->view('docs.docs');
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
Route::view('/documentation-contribution-guide', 'docs.contribution')
->name('documentation-contribution-guide');

Route::redirect('/docs/', '/docs/'.Docs::DEFAULT_VERSION);
Route::redirect('/docs/', '/docs/'.Docs::DEFAULT_VERSION.'/'.Docs::DEFAULT_DOCUMENT);

Route::get('/status/{version?}', [DocsController::class, 'status'])
->whereIn('version', Docs::SUPPORT_VERSIONS)
Expand Down

0 comments on commit 72b33a8

Please sign in to comment.