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
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;
}
Usage
{{ addWwwToUrl(url()->current()) }}
That only gives url for index page. What about other dynamic pages ??
Please consider adding some explanation and details to your desired result and show us what have you tried that we could look.
Updated Question
@TanjaForsberg check updated answer
I'm getting this error
Undefined index: path