File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -728,6 +728,19 @@ public function forceScheme($scheme)
728728 $ this ->forceScheme = $ scheme ? $ scheme .':// ' : null ;
729729 }
730730
731+ /**
732+ * Force the use of the HTTPS scheme for all generated URLs.
733+ *
734+ * @param bool $force
735+ * @return void
736+ */
737+ public function forceHttps ($ force = true )
738+ {
739+ if ($ force ) {
740+ $ this ->forceScheme ('https ' );
741+ }
742+ }
743+
731744 /**
732745 * Set the forced root URL.
733746 *
Original file line number Diff line number Diff line change 3030 * @method static void defaults(array $defaults)
3131 * @method static array getDefaultParameters()
3232 * @method static void forceScheme(string|null $scheme)
33+ * @method static void forceHttps(bool $force = true)
3334 * @method static void forceRootUrl(string|null $root)
3435 * @method static \Illuminate\Routing\UrlGenerator formatHostUsing(\Closure $callback)
3536 * @method static \Illuminate\Routing\UrlGenerator formatPathUsing(\Closure $callback)
Original file line number Diff line number Diff line change @@ -716,6 +716,20 @@ public function testForceRootUrl()
716716 $ this ->assertSame ('https://www.bar.com/foo ' , $ url ->route ('plain ' ));
717717 }
718718
719+ public function testForceHttps ()
720+ {
721+ $ url = new UrlGenerator (
722+ $ routes = new RouteCollection ,
723+ Request::create ('http://www.foo.com/ ' )
724+ );
725+
726+ $ url ->forceHttps ();
727+ $ route = new Route (['GET ' ], '/foo ' , ['as ' => 'plain ' ]);
728+ $ routes ->add ($ route );
729+
730+ $ this ->assertSame ('https://www.foo.com/foo ' , $ url ->route ('plain ' ));
731+ }
732+
719733 public function testPrevious ()
720734 {
721735 $ url = new UrlGenerator (
You can’t perform that action at this time.
0 commit comments