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