1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Menu\Laravel; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Traits\Macroable; |
6
|
|
|
use Spatie\Menu\Menu as BaseMenu; |
7
|
|
|
|
8
|
|
|
class Menu extends BaseMenu |
9
|
|
|
{ |
10
|
|
|
use Macroable; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Set all relevant children active based on the current request's URL. |
14
|
|
|
* |
15
|
|
|
* /, /about, /contact => request to /about will set the about link active. |
16
|
|
|
* |
17
|
|
|
* /en, /en/about, /en/contact => request to /en won't set /en active if the request root |
18
|
|
|
* is set to /en. |
19
|
|
|
* |
20
|
|
|
* @param string $requestRoot If the link's URL is an exact match with the request root, the |
21
|
|
|
* link won't be set active. This behavior is to avoid having home |
22
|
|
|
* links active on every request. |
23
|
|
|
* |
24
|
|
|
* @return $this |
25
|
|
|
*/ |
26
|
|
|
public function setActiveFromRequest(string $requestRoot = '') |
27
|
|
|
{ |
28
|
|
|
return $this->setActive(app('request')->url(), $requestRoot); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $path |
33
|
|
|
* @param string $text |
34
|
|
|
* @param array $parameters |
35
|
|
|
* @param bool|null $secure |
36
|
|
|
* |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
|
|
public function url(string $path, string $text, $parameters = [], $secure = null) |
40
|
|
|
{ |
41
|
|
|
return Link::url($path, $text, $parameters, $secure); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $action |
46
|
|
|
* @param string $text |
47
|
|
|
* @param array $parameters |
48
|
|
|
* @param bool $absolute |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function action(string $action, string $text, $parameters = [], $absolute = true) |
53
|
|
|
{ |
54
|
|
|
return Link::action($action, $text, $parameters, $absolute); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $name |
59
|
|
|
* @param string $text |
60
|
|
|
* @param array $parameters |
61
|
|
|
* @param bool $absolute |
62
|
|
|
* @param \Illuminate\Routing\Route|null $route |
63
|
|
|
* |
64
|
|
|
* @return $this |
65
|
|
|
*/ |
66
|
|
|
public function route(string $name, string $text, $parameters = [], $absolute = true, $route = null) |
67
|
|
|
{ |
68
|
|
|
return Link::route($name, $text, $parameters, $absolute, $route); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|