MainController.php
9.4 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
namespace App\Http\Controllers;
use App\Models\Ad_employer;
use App\Models\Category;
use App\Models\Education;
use App\Models\Employer;
use App\Models\Job_title;
use App\Models\News;
use App\Models\reclame;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use App\Classes\StatusUser;
class MainController extends Controller
{
// Главная страница публичной части
public function index() {
$news = News::query()->orderBy('id')->limit(6)->get();
$categories = Category::query()->selectRaw('count(ad_employers.id) as cnt, categories.*')
->join('ad_employers', 'ad_employers.category_id', '=', 'categories.id')
->OrderByDesc('created_at')
->GroupBy('categories.id')
->get();
$employers = Employer::query()->orderBy('id')->limit(20)->get();
return view('index', compact('news', 'categories', 'employers'));
}
public function search_vacancies(Request $request) {
if ($request->has('search')) {
$search = $request->get('search');
$job_titles = Job_title::query()->where('name', 'LIKE', "%$search%")->first();
if (isset($job_titles->id))
if ($job_titles->id > 0)
return redirect()->route('vacancies', ['job' => $job_titles->id]);
}
}
public function vacancies(Request $request) {
//должности
$Job_title = Job_title::query()->orderBy('name')->get();
$categories = Category::query()->selectRaw('count(ad_employers.id) as cnt, categories.*')
->selectRaw('min(ad_employers.salary) as min_salary, max(ad_employers.salary) as max_salary')
->join('ad_employers', 'ad_employers.category_id', '=', 'categories.id')
->join('ad_jobs', 'ad_jobs.ad_employer_id', '=', 'ad_employers.id');
//категории и вакансии
if (($request->has('job')) && ($request->get('job') > 0)) {
$categories = $categories->Where('job_title_id', '=', $request->get('job'))
->OrderByDesc('created_at')
->GroupBy('categories.id')
->get();
} else {
$categories = $categories->OrderByDesc('created_at')
->GroupBy('categories.id')
->get();
}
if ($request->ajax()) {
return view('ajax.vacancies', compact('categories'));
} else {
return view('vacancies', compact('Job_title', 'categories'));
}
}
//Вакансии категория детальная
public function list_vacancies(Category $categories, Request $request) {
if (isset(Auth()->user()->id))
$uid = Auth()->user()->id;
else
$uid = 0;
$Query = Ad_employer::with('jobs')->
with('cat')->
with('employer')->
whereHas('jobs_code', function ($query) use ($request) {
if ($request->ajax()) {
if (null !== ($request->get('job')) && ($request->get('job') !== 0)) {
$query->where('job_title_id', $request->get('job'));
}
}
})
->select('ad_employers.*');
if ($categories->id > 0) {
$Query = $Query->where('category_id', '=', $categories->id);
$Name_categori = Category::query()->where('id', '=', $categories->id)->get();
}
if ($request->get('sort')) {
$sort = $request->get('sort');
switch ($sort) {
case 'name_up': $Query = $Query->orderBy('name')->orderBy('id'); break;
case 'name_down': $Query = $Query->orderByDesc('name')->orderby('id'); break;
case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break;
case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break;
case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break;
default: $Query = $Query->orderBy('id')->orderby('updated_at'); break;
}
}
$Job_title = Job_title::query()->OrderBy('name')->get();
$Query_count = $Query->count();
$Query = $Query->OrderBy('updated_at')->paginate(3);
$Reclama = reclame::query()->limit(3)->get();
if ($request->ajax()) {
return view('ajax.list_vacancies', compact('Query',
'Query_count',
'Name_categori',
'Reclama',
'categories',
'uid'));
} else {
//Вернуть все
return view('list_vacancies', compact('Query',
'Query_count',
'Reclama',
'Name_categori',
'categories',
'Job_title',
'uid'));
}
}
// Образование
public function education(Request $request) {
$educations = Education::query();
if (($request->has('search')) && (!empty($request->get('search')))) {
$search = trim($request->get('search'));
$educations = $educations->where('name', 'LIKE', "%$search%");
}
if ($request->get('sort')) {
$sort = $request->get('sort');
switch ($sort) {
case 'name_up': $educations = $educations->orderBy('name')->orderBy('id'); break;
case 'name_down': $educations = $educations->orderByDesc('name')->orderby('id'); break;
case 'created_at_up': $educations = $educations->OrderBy('created_at')->orderBy('id'); break;
case 'created_at_down': $educations = $educations->orderByDesc('created_at')->orderBy('id'); break;
case 'default': $educations = $educations->orderBy('id')->orderby('updated_at'); break;
default: $educations = $educations->orderBy('id')->orderby('updated_at'); break;
}
}
$count_edu = $educations->count();
$educations = $educations->paginate(6);
if ($request->ajax()) {
return view('ajax.education', compact('educations'));
} else {
return view('education', compact('educations', 'count_edu'));
}
}
// Контакты
public function contacts() {
return view('contacts');
}
// Вход в личный кабинет
public function input_login(Request $request)
{
$rules = [
'email' => 'required|string|email',
'password' => 'required|string',
];
$messages = [
'required' => 'Укажите обязательное поле «:attribute»',
'email' => 'Введите корректный email',
'min' => [
'string' => 'Поле «:attribute» должно быть не меньше :min символов',
'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
],
'max' => [
'string' => 'Поле «:attribute» должно быть не больше :max символов',
'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
],
];
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails()) {
return redirect()->route('index')->with('Error', "Email или пароль невалидный");
} else {
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials, $request->has('remember'))) {
if (is_null(Auth::user()->email_verified_at)) {
Auth::logout();
return json_encode(Array("ERROR" => "Адрес почты не подтвержден"));
}
if (Auth::user()->is_worker) {
return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));
} else {
return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));
}
return json_encode(Array("SUCCESS" => "Вы успешно вошли в личный кабинет"));
//->route('index')
//->with('success', 'Вы вошли в личный кабинет.');
} else {
return json_encode(Array("ERROR" => "Неверный логин или пароль!"));
}
}
}
}