-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUrlGenerator.php
60 lines (48 loc) · 1.61 KB
/
UrlGenerator.php
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace App\Larabookir;
use Illuminate\Routing\UrlGenerator as base;;
class UrlGenerator extends base
{
protected $appendUnNamedParametersToQuery=true;
public function route($name, $parameters = [], $absolute = true)
{
$parameters = (array)$parameters;
if (!key_exists('lang', $parameters)) {
$parameters['lang'] = \App::getLocale();
$this->appendUnNamedParametersToQuery=false;
}
return parent::route($name, $parameters, $absolute); // TODO: Change the autogenerated stub
}
/**
* Add a query string to the URI.
*
* @param string $uri
* @param array $parameters
* @return mixed|string
*/
protected function addQueryString($uri, array $parameters)
{
// If the URI has a fragment, we will move it to the end of this URI since it will
// need to come after any query string that may be added to the URL else it is
// not going to be available. We will remove it then append it back on here.
if (! is_null($fragment = parse_url($uri, PHP_URL_FRAGMENT))) {
$uri = preg_replace('/#.*/', '', $uri);
}
if($this->appendUnNamedParametersToQuery)
$uri .= $this->getRouteQueryString($parameters);
return is_null($fragment) ? $uri : $uri."#{$fragment}";
}
public function to($path, $extra = [], $secure = null)
{
if(!starts_with($path,['http','www','.','//','#', 'mailto:', 'tel:',])){
$extra=(array) $extra;
if (!key_exists('lang', $extra))
$path = \App::getLocale().left_ch($path);
else {
$path = $extra['lang'] . left_ch($path);
unset($extra['lang']);
}
}
return parent::to($path, $extra, $secure); // TODO: Change the autogenerated stub
}
}