Created
August 5, 2020 13:30
-
-
Save minedun6/c9e466a3b5805cc99b4c6f1a5b6f7419 to your computer and use it in GitHub Desktop.
Here's how you can temporally force a different host on the #laravelphp URL generator. Useful when you're generating URLs for your frontend SPA! @m1guelpf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (! function_exists('frontend_url')) { | |
function frontendUrl($path = null, $parameters = [], $secure = null) : string { | |
$builder = url(); | |
$builder->forceRootUrl( | |
app()->isProduction() ? 'https://xxxx.xxxx' : 'http://localhost:3000/'; | |
); | |
return tap($builder->to($path, $parameters, $secure), fn () => $builder->forceRootUrl(null)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment