File tree 2 files changed +36
-3
lines changed
2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Http \Controllers ;
4
+
5
+ use Illuminate \Http \Request ;
6
+ use Illuminate \Support \Facades \Http ;
7
+ use Illuminate \Support \Str ;
8
+
9
+ class ShowDocController extends Controller
10
+ {
11
+ /**
12
+ * @throws \Illuminate\Http\Client\ConnectionException
13
+ */
14
+ public function __invoke (Request $ request )
15
+ {
16
+ $ rootUrl = 'https://laravel.com/docs/ ' ;
17
+ $ initialPath = Str::remove ('docs/ ' , $ request ->path ());
18
+
19
+ $ response = Http::withOptions (['allow_redirects ' => false ])->get ($ rootUrl .$ initialPath );
20
+
21
+ if ($ response ->redirect ()) {
22
+ $ redirectUrl = $ response ->header ('Location ' );
23
+ \Log::info ('Redirecting to: ' .$ redirectUrl );
24
+
25
+ $ parsedUrl = parse_url ($ redirectUrl );
26
+ $ redirectPath = $ parsedUrl ['path ' ] ?? '/ ' ;
27
+
28
+ return redirect ()->to ($ redirectPath );
29
+ }
30
+
31
+ return $ response ->body ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ use App \Http \Controllers \ShowDocController ;
3
4
use Illuminate \Support \Facades \Route ;
4
5
5
- Route::get ('/ ' , function () {
6
- return view ('welcome ' );
7
- });
6
+
7
+ Route::get ('{any?} ' , ShowDocController::class)->where ('any ' , '.* ' );
You can’t perform that action at this time.
0 commit comments