|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\ViewComposers; |
|
4
|
|
|
|
|
5
|
|
|
use Facades\App\Services\WhichPortal; |
|
6
|
|
|
use Illuminate\View\View; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Illuminate\Support\Facades\Lang; |
|
9
|
|
|
use Illuminate\Support\Facades\Log; |
|
10
|
|
|
|
|
11
|
|
|
class BreadcrumbsComposer |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The request instance. |
|
15
|
|
|
* |
|
16
|
|
|
* @var \Illuminate\Http\Request |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $request; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Initialize a new composer instance. |
|
22
|
|
|
* |
|
23
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
|
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(Request $request) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->request = $request; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Bind data to the view. |
|
33
|
|
|
* |
|
34
|
|
|
* @param \Illuminate\View\View $view |
|
|
|
|
|
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
|
|
public function compose(View $view) |
|
38
|
|
|
{ |
|
39
|
|
|
$segments = $this->parseSegments(); |
|
40
|
|
|
$breadcrumbs_lang = Lang::get('common/breadcrumbs')['applicant']; |
|
41
|
|
|
|
|
42
|
|
|
if (WhichPortal::isManagerPortal()) { |
|
43
|
|
|
$segments = $segments->slice(1); |
|
44
|
|
|
$breadcrumbs_lang = Lang::get('common/breadcrumbs')['manager']; |
|
45
|
|
|
} elseif (WhichPortal::isHrPortal()) { |
|
46
|
|
|
$segments = $segments->slice(1); |
|
47
|
|
|
$breadcrumbs_lang = Lang::get('common/breadcrumbs')['hr']; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$view->with('breadcrumbs', $segments); |
|
51
|
|
|
$view->with('breadcrumbs_lang', $breadcrumbs_lang); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Parse the request route segments. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Illuminate\Support\Collection |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function parseSegments() |
|
60
|
|
|
{ |
|
61
|
|
|
return collect($this->request->segments())->mapWithKeys(function ($segment, $key) { |
|
62
|
|
|
return [ |
|
63
|
|
|
$segment => implode('/', array_slice($this->request->segments(), 0, $key + 1)), |
|
64
|
|
|
]; |
|
65
|
|
|
}); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|