engelsystem/src/Routing/UrlGenerator.php

26 lines
539 B
PHP
Raw Normal View History

<?php
namespace Engelsystem\Routing;
class UrlGenerator
{
/**
* @param string $path
* @param array $parameters
* @return string
*/
public static function to($path, $parameters = [])
{
$path = '/' . ltrim($path, '/');
2017-08-31 17:30:54 +02:00
$request = app('request');
$uri = $request->getUriForPath($path);
if (!empty($parameters) && is_array($parameters)) {
$parameters = http_build_query($parameters);
$uri .= '?' . $parameters;
}
return $uri;
}
}