MyServiceProvider.php
3.92 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace App\Providers;
use App\Models\Company;
use App\Models\ContentRoles;
use App\Models\Employer;
use App\Models\Job_title;
use App\Models\Worker;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class MyServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$views = ['admin.job_titles.parent_id'];
View::composer($views,
function($view)
{
static $items = null;
if (is_null($items)) {
$items = Job_title::query()->
orderByDesc('sort')->
orderBy('name')->
active()->
get();
$parent = 0;
$view->with(['items' => $items, 'parent' => $parent]);
} else {
$view->with(['items' => $items]);
}
}
);
$views2 = ['layout.admin', 'admin.index'];
View::composer($views2,
function($view){
$id = Auth::user()->id;
$is_manager = Auth::user()->is_manager;
$admin = Auth::user()->admin;
$contents = ContentRoles::query()->get();
$query = DB::select(DB::raw('SELECT count(*) as MsgCount
FROM messages m1
Where ((m1.flag_new = 1) and (m1.to_user_id = :uid))
'), ['uid' => $id]
);
$view->with(['MsgCount' => $query[0]->MsgCount,
'UserId' => $id,
'is_manager' => $is_manager,
'admin' => $admin,
'contents' => $contents]);
}
);
$views3 = ['layout.frontend', 'index'];
View::composer($views3,
function($view){
$id = Auth::user();
$companies = Company::query()->limit(1)->get();
$jobs = Job_title::query()->where('is_remove', '=', '0')->get();
$view->with(['UserId' => $id, 'companies' => $companies, 'jobs' => $jobs]);
}
);
$view1 = ['employers.menu', 'employers.emblema', 'employers.send_all'];
View::composer($view1,
function($view){
$user = Auth::user();
$id = $user->id;
$employer = Employer::query()->where('user_id', $id)->get();
$id_employer = $employer[0]->id;
$view->with(['id_employer' => $id_employer, 'Employer' => $employer]);
}
);
$view_worker = ['workers.emblema'];
View::composer($view_worker,
function($view_worker) {
$user = Auth::user();
$id = $user->id;
$Worker = Worker::query()->where('user_id', $id)->get();
if (isset($Worker[0]->id)) {
$id_worker = $Worker[0]->id;
} else {
$id_worker = 0;
}
$view_worker->with(['id_worker' => $id_worker, 'Worker' => $Worker, 'User' => $user]);
}
);
$view_job_title = ['modals.register'];
View::composer($view_job_title,
function($view_job_title) {
$Job_titles = Job_title::query()->where('is_remove', '=', '0')->
where('is_bd', '=' , '1')->get();
$view_job_title->with(['Job_titles' => $Job_titles]);
}
);
}
}