summaryrefslogtreecommitdiff
path: root/src/Http/UrlGenerator.php
blob: 132fefc753fc6853499daa81a5a1dd2d63742b71 (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\Http;

class UrlGenerator
{
    /**
     * @param string $path
     * @param array  $parameters
     * @return string
     */
    public 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;
    }
}