Created
August 5, 2020 13:44
-
-
Save minedun6/3194dba2a48a41404330c62c67dce667 to your computer and use it in GitHub Desktop.
Something I struggled with is that `to()` adds the $parameters to the path by default `success/verify_email` instead of `success?type=verify_email`. So I've slightly adjusted your example to match my needs. @devgummibeer
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 | |
namespace App\Providers; | |
use Illuminate\Contracts\Routing\UrlGenerator; | |
use Illuminate\Support\ServiceProvider; | |
use Arr; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
app(UrlGenerator::class)->macro('frontend', function (string $uri, array $parameters = []): string { | |
$this->forceRootUrl(config('app.frontend_url')); | |
$path = parse_url($uri, PHP_URL_PATH); | |
$query = parse_url($uri, PHP_URL_QUERY); | |
parse_str($query, $query); | |
$query = Arr::query( | |
array_merge($query, $parameters) | |
); | |
return tap( | |
$this->to($path, ($query ? '?' . $query : '')), | |
fn => $this->forceRootUrl(null) | |
); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment