1
|
|
|
<?php namespace Arcanedev\Breadcrumbs; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Trait HasBreadcrumbs |
5
|
|
|
* |
6
|
|
|
* @package Arcanedev\Breadcrumbs |
7
|
|
|
* @author ARCANEDEV <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
trait HasBreadcrumbs |
10
|
|
|
{ |
11
|
|
|
/* ----------------------------------------------------------------- |
12
|
|
|
| Properties |
13
|
|
|
| ----------------------------------------------------------------- |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Breadcrumbs container name. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $breadcrumbsContainer = 'public'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Breadcrumbs items collection. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private $breadcrumbsItems = []; |
29
|
|
|
|
30
|
|
|
/* ----------------------------------------------------------------- |
31
|
|
|
| Getters & Setters |
32
|
|
|
| ----------------------------------------------------------------- |
33
|
|
|
*/ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Set breadcrumbs container name. |
37
|
|
|
* |
38
|
|
|
* @param string $name |
39
|
|
|
* |
40
|
|
|
* @return self |
41
|
|
|
*/ |
42
|
4 |
|
protected function setBreadcrumbsContainer($name) |
43
|
|
|
{ |
44
|
4 |
|
$this->breadcrumbsContainer = $name; |
45
|
|
|
|
46
|
4 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the breadcrumbs home item (root). |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
4 |
|
protected function getBreadcrumbsHomeItem() |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
4 |
|
'title' => trans('breadcrumbs::items.home'), |
58
|
4 |
|
'url' => route(config('breadcrumbs.home-route', 'public::home')), |
59
|
|
|
'data' => [], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/* ----------------------------------------------------------------- |
64
|
|
|
| Main Functions |
65
|
|
|
| ----------------------------------------------------------------- |
66
|
|
|
*/ |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Register a breadcrumb. |
70
|
|
|
* |
71
|
|
|
* @param string $container |
72
|
|
|
* @param array $item |
73
|
|
|
*/ |
74
|
4 |
|
protected function registerBreadcrumbs($container, array $item = []) |
75
|
|
|
{ |
76
|
4 |
|
$this->setBreadcrumbsContainer($container); |
77
|
|
|
|
78
|
|
|
breadcrumbs()->register('main', function(Builder $bc) use ($item) { |
79
|
4 |
|
if (empty($item)) { |
80
|
4 |
|
$item = $this->getBreadcrumbsHomeItem(); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
4 |
|
$bc->push($item['title'], $item['url'], $item['data'] ?? []); |
84
|
4 |
|
}); |
85
|
4 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Load all breadcrumbs. |
89
|
|
|
*/ |
90
|
4 |
|
protected function loadBreadcrumbs() |
91
|
|
|
{ |
92
|
|
|
breadcrumbs()->register($this->breadcrumbsContainer, function(Builder $bc) { |
93
|
4 |
|
$bc->parent('main'); |
94
|
|
|
|
95
|
4 |
|
if ( ! empty($this->breadcrumbsItems)) { |
96
|
4 |
|
foreach ($this->breadcrumbsItems as $crumb) { |
97
|
4 |
|
$bc->push($crumb['title'], $crumb['url'], $crumb['data'] ?? []); |
98
|
|
|
} |
99
|
|
|
} |
100
|
4 |
|
}); |
101
|
4 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Add breadcrumb. |
105
|
|
|
* |
106
|
|
|
* @param string $title |
107
|
|
|
* @param string $url |
108
|
|
|
* @param array $data |
109
|
|
|
* |
110
|
|
|
* @return self |
111
|
|
|
*/ |
112
|
4 |
|
protected function addBreadcrumb($title, $url = '', array $data = []) |
113
|
|
|
{ |
114
|
4 |
|
$this->breadcrumbsItems[] = compact('title', 'url', 'data'); |
115
|
|
|
|
116
|
4 |
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Add breadcrumb with route. |
121
|
|
|
* |
122
|
|
|
* @param string $title |
123
|
|
|
* @param string $route |
124
|
|
|
* @param array $parameters |
125
|
|
|
* @param array $data |
126
|
|
|
* |
127
|
|
|
* @return self |
128
|
|
|
*/ |
129
|
4 |
|
protected function addBreadcrumbRoute($title, $route, array $parameters = [], array $data = []) |
130
|
|
|
{ |
131
|
4 |
|
return $this->addBreadcrumb($title, route($route, $parameters), $data); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
It seems like you are assigning to a variable which was imported through a
use
statement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope