Skip to content

Instantly share code, notes, and snippets.

@minedun6
Created August 5, 2020 13:30
Show Gist options
  • Save minedun6/c9e466a3b5805cc99b4c6f1a5b6f7419 to your computer and use it in GitHub Desktop.
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
<?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