0

I'm using https://example.com version of url for my laravel built app site.

I want <link rel="canonical" hreflang="en-us" href="https://www.upscaleadventures.com/" /> as my canonical tag

{{url()->current()}} only gives the URL that I've setup as default. <link rel="canonical" hreflang="en-us" href="https://upscaleadventures.com/" /> version in my case.

How do I print https://www.upscaleadventures.com/ version of url in Laravel

psudo
  • 1,341
  • 3
  • 24
  • 69

1 Answers1

2

You may set APP_URL in your .env file to https://example.com, then access it via

env("APP_URL", "somedefaultvalue");

Edit

You may consider create a helper to convert your URL

function addWwwToUrl($url) {

   $bits = parse_url($url);

   $newHost = substr($bits["host"],0,4) !== "www." ? "www." . $bits["host"] : $bits["host"];

   $newUrl = $bits["scheme"]. "://" . $newHost . (isset($bits["port"]) ? ":" . $bits["port"] : "" ) . (isset($bits["path"]) ? $bits["path"] : "" ) . (!empty($bits["query"])? "?" . $bits["query"]: "");

   return $newUrl;
}

Reference

Usage

{{ addWwwToUrl(url()->current()) }}
Matthew Schlachter
  • 3,250
  • 1
  • 12
  • 26
Foued MOUSSI
  • 4,643
  • 3
  • 19
  • 39