]> BookStack Code Mirror - bookstack/blob - app/Http/Request.php
Fixed base URL starting slash usage
[bookstack] / app / Http / Request.php
1 <?php
2
3 namespace BookStack\Http;
4
5 use Illuminate\Http\Request as LaravelRequest;
6
7 class Request extends LaravelRequest
8 {
9     /**
10      * Override the default request methods to get the scheme and host
11      * to directly use the custom APP_URL, if set.
12      *
13      * @return string
14      */
15     public function getSchemeAndHttpHost()
16     {
17         $appUrl = config('app.url', null);
18
19         if ($appUrl) {
20             return implode('/', array_slice(explode('/', $appUrl), 0, 3));
21         }
22
23         return parent::getSchemeAndHttpHost();
24     }
25
26     /**
27      * Override the default request methods to get the base URL
28      * to directly use the custom APP_URL, if set.
29      * The base URL never ends with a / but should start with one if not empty.
30      *
31      * @return string
32      */
33     public function getBaseUrl()
34     {
35         $appUrl = config('app.url', null);
36
37         if ($appUrl) {
38             return '/' . rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
39         }
40
41         return parent::getBaseUrl();
42     }
43 }