summaryrefslogtreecommitdiff
path: root/src/Routing/UrlGenerator.php
blob: 33eef7b03b54cce521cc0c4d166e6b9ef1ece8d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

namespace Engelsystem\Routing;

class UrlGenerator
{
    /**
     * @param string $path
     * @param array  $parameters
     * @return string
     */
    public static function to($path, $parameters = [])
    {
        $path = '/' . ltrim($path, '/');
        $request = app('request');
        $uri = $request->getUriForPath($path);

        if (!empty($parameters) && is_array($parameters)) {
            $parameters = http_build_query($parameters);
            $uri .= '?' . $parameters;
        }

        return $uri;
    }
}