MainController.php
7.2 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
<?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;
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) {
$Query = Ad_employer::with('jobs')->
with('cat')->
with('employer')->
whereHas('jobs_code', function ($query) use ($request) {
if ($request->ajax()) {
if (null !== ($request->get('job'))) {
$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();
}
$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'));
} else {
//Вернуть все
return view('list_vacancies', compact('Query',
'Query_count',
'Reclama',
'Name_categori',
'categories',
'Job_title'));
}
}
// Образование
public function education(Request $request) {
$educations = Education::query();
if ($request->has('search')) {
$search = trim($request->has('search'));
$educations = $educations->where('name', 'LIKE', "%$search%");
}
$count_edu = $educations->count();
$educations = $educations->paginate(6);
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 Array("ERROR" => "Емайл невалидный");//$validator; //back()->withErrors($validator)->withInput();
} else {
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials, $request->has('remember'))) {
if (is_null(Auth::user()->email_verified_at)) {
Auth::logout();
return Array("ERROR" => "Адрес почты не подтвержден");
}
if (Auth::user()->is_worker) {
return Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl());
} else {
return Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl());
}
return Array("SUCCESS" => "Вы успешно вошли в личный кабинет");
//->route('index')
//->with('success', 'Вы вошли в личный кабинет.');
} else {
return Array("ERROR" => "Неверный логин или пароль!");
}
}
}
}