Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Illuminate/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,19 @@ public function forceScheme($scheme)
$this->forceScheme = $scheme ? $scheme.'://' : null;
}

/**
* Force the use of the HTTPS scheme for all generated URLs.
*
* @param bool $force
* @return void
*/
public function forceHttps($force = true)
{
if ($force) {
$this->forceScheme('https');
}
}

/**
* Set the forced root URL.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @method static void defaults(array $defaults)
* @method static array getDefaultParameters()
* @method static void forceScheme(string|null $scheme)
* @method static void forceHttps(bool $force = true)
* @method static void forceRootUrl(string|null $root)
* @method static \Illuminate\Routing\UrlGenerator formatHostUsing(\Closure $callback)
* @method static \Illuminate\Routing\UrlGenerator formatPathUsing(\Closure $callback)
Expand Down
14 changes: 14 additions & 0 deletions tests/Routing/RoutingUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,20 @@ public function testForceRootUrl()
$this->assertSame('https://www.bar.com/foo', $url->route('plain'));
}

public function testForceHttps()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
Request::create('http://www.foo.com/')
);

$url->forceHttps();
$route = new Route(['GET'], '/foo', ['as' => 'plain']);
$routes->add($route);

$this->assertSame('https://www.foo.com/foo', $url->route('plain'));
}

public function testPrevious()
{
$url = new UrlGenerator(
Expand Down