Commit 136bdb8d2779359647ea88b63e4c7222d6d0af6c

Authored by Андрей Ларионов
1 parent dc2a9a8762

Статус избранные

Showing 2 changed files with 2 additions and 2 deletions Inline Diff

app/Http/Controllers/EmployerController.php
1 <?php 1 <?php
2 2
3 namespace App\Http\Controllers; 3 namespace App\Http\Controllers;
4 4
5 use App\Classes\RusDate; 5 use App\Classes\RusDate;
6 use App\Classes\Tools; 6 use App\Classes\Tools;
7 use App\Http\Requests\FlotRequest; 7 use App\Http\Requests\FlotRequest;
8 use App\Http\Requests\MessagesRequiest; 8 use App\Http\Requests\MessagesRequiest;
9 use App\Http\Requests\VacancyRequestEdit; 9 use App\Http\Requests\VacancyRequestEdit;
10 use App\Http\Requests\VacansiaRequiest; 10 use App\Http\Requests\VacansiaRequiest;
11 use App\Mail\MailSotrudnichestvo; 11 use App\Mail\MailSotrudnichestvo;
12 use App\Mail\SendAllMessages; 12 use App\Mail\SendAllMessages;
13 use App\Models\Ad_employer; 13 use App\Models\Ad_employer;
14 use App\Models\Ad_jobs; 14 use App\Models\Ad_jobs;
15 use App\Models\ad_response; 15 use App\Models\ad_response;
16 use App\Models\Category; 16 use App\Models\Category;
17 use App\Models\Education; 17 use App\Models\Education;
18 use App\Models\Employer; 18 use App\Models\Employer;
19 use App\Models\employers_main; 19 use App\Models\employers_main;
20 use App\Models\Flot; 20 use App\Models\Flot;
21 use App\Models\Job_title; 21 use App\Models\Job_title;
22 use App\Models\Like_vacancy; 22 use App\Models\Like_vacancy;
23 use App\Models\Like_worker; 23 use App\Models\Like_worker;
24 use App\Models\Message; 24 use App\Models\Message;
25 use App\Models\Worker; 25 use App\Models\Worker;
26 use Carbon\Carbon; 26 use Carbon\Carbon;
27 use Illuminate\Auth\Events\Registered; 27 use Illuminate\Auth\Events\Registered;
28 use Illuminate\Database\Eloquent\Builder; 28 use Illuminate\Database\Eloquent\Builder;
29 use Illuminate\Database\Eloquent\Model; 29 use Illuminate\Database\Eloquent\Model;
30 use Illuminate\Foundation\Auth\User; 30 use Illuminate\Foundation\Auth\User;
31 use Illuminate\Http\Request; 31 use Illuminate\Http\Request;
32 use Illuminate\Support\Facades\Auth; 32 use Illuminate\Support\Facades\Auth;
33 use Illuminate\Support\Facades\Hash; 33 use Illuminate\Support\Facades\Hash;
34 use Illuminate\Support\Facades\Mail; 34 use Illuminate\Support\Facades\Mail;
35 use Illuminate\Support\Facades\Storage; 35 use Illuminate\Support\Facades\Storage;
36 use App\Models\User as User_Model; 36 use App\Models\User as User_Model;
37 use Illuminate\Support\Facades\Validator; 37 use Illuminate\Support\Facades\Validator;
38 38
39 class EmployerController extends Controller 39 class EmployerController extends Controller
40 { 40 {
41 public function vacancie($vacancy, Request $request) { 41 public function vacancie($vacancy, Request $request) {
42 $title = 'Заголовок вакансии'; 42 $title = 'Заголовок вакансии';
43 $Query = Ad_employer::with('jobs')-> 43 $Query = Ad_employer::with('jobs')->
44 with('cat')-> 44 with('cat')->
45 with('employer')-> 45 with('employer')->
46 with('jobs_code')-> 46 with('jobs_code')->
47 select('ad_employers.*')-> 47 select('ad_employers.*')->
48 where('id', '=', $vacancy)->get(); 48 where('id', '=', $vacancy)->get();
49 49
50 if (isset(Auth()->user()->id)) 50 if (isset(Auth()->user()->id))
51 $uid = Auth()->user()->id; 51 $uid = Auth()->user()->id;
52 else 52 else
53 $uid = 0; 53 $uid = 0;
54 $title = $Query[0]->name; 54 $title = $Query[0]->name;
55 if ($request->ajax()) { 55 if ($request->ajax()) {
56 return view('ajax.vacance-item', compact('Query','uid')); 56 return view('ajax.vacance-item', compact('Query','uid'));
57 } else { 57 } else {
58 return view('vacance-item', compact('title', 'Query', 'uid')); 58 return view('vacance-item', compact('title', 'Query', 'uid'));
59 } 59 }
60 } 60 }
61 61
62 public function logout() { 62 public function logout() {
63 Auth::logout(); 63 Auth::logout();
64 return redirect()->route('index') 64 return redirect()->route('index')
65 ->with('success', 'Вы вышли из личного кабинета'); 65 ->with('success', 'Вы вышли из личного кабинета');
66 } 66 }
67 67
68 public function cabinet() { 68 public function cabinet() {
69 $id = Auth()->user()->id; 69 $id = Auth()->user()->id;
70 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 70 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
71 WhereHas('users', 71 WhereHas('users',
72 function (Builder $query) use ($id) {$query->Where('id', $id); 72 function (Builder $query) use ($id) {$query->Where('id', $id);
73 })->get(); 73 })->get();
74 return view('employers.cabinet45', compact('Employer')); 74 return view('employers.cabinet45', compact('Employer'));
75 } 75 }
76 76
77 public function cabinet_save(Employer $Employer, Request $request) { 77 public function cabinet_save(Employer $Employer, Request $request) {
78 $params = $request->all(); 78 $params = $request->all();
79 $params['user_id'] = Auth()->user()->id; 79 $params['user_id'] = Auth()->user()->id;
80 $id = $Employer->id; 80 $id = $Employer->id;
81 81
82 if ($request->has('logo')) { 82 if ($request->has('logo')) {
83 if (!empty($Employer->logo)) { 83 if (!empty($Employer->logo)) {
84 Storage::delete($Employer->logo); 84 Storage::delete($Employer->logo);
85 } 85 }
86 $params['logo'] = $request->file('logo')->store("employer/$id", 'public'); 86 $params['logo'] = $request->file('logo')->store("employer/$id", 'public');
87 } 87 }
88 88
89 $Employer->update($params); 89 $Employer->update($params);
90 90
91 return redirect()->route('employer.cabinet')->with('success', 'Данные были успешно сохранены'); 91 return redirect()->route('employer.cabinet')->with('success', 'Данные были успешно сохранены');
92 } 92 }
93 93
94 public function save_add_flot(FlotRequest $request) { 94 public function save_add_flot(FlotRequest $request) {
95 // отмена 95 // отмена
96 $params = $request->all(); 96 $params = $request->all();
97 97
98 if ($request->has('image')) { 98 if ($request->has('image')) {
99 $params['image'] = $request->file('image')->store("flot", 'public'); 99 $params['image'] = $request->file('image')->store("flot", 'public');
100 } 100 }
101 Flot::create($params); 101 Flot::create($params);
102 $data_flots = Flot::query()->where('employer_id', $request->get('employer_if'))->get(); 102 $data_flots = Flot::query()->where('employer_id', $request->get('employer_if'))->get();
103 return redirect()->route('employer.cabinet')->with('success', 'Новый корабль был добавлен'); 103 return redirect()->route('employer.cabinet')->with('success', 'Новый корабль был добавлен');
104 } 104 }
105 105
106 public function delete_flot(Flot $Flot) { 106 public function delete_flot(Flot $Flot) {
107 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get(); 107 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get();
108 108
109 if (isset($Flot->id)) $Flot->delete(); 109 if (isset($Flot->id)) $Flot->delete();
110 return redirect()->route('employer.cabinet')->with('success', 'Корабль был удален'); 110 return redirect()->route('employer.cabinet')->with('success', 'Корабль был удален');
111 } 111 }
112 112
113 // Форма добавления вакансий 113 // Форма добавления вакансий
114 public function cabinet_vacancie() { 114 public function cabinet_vacancie() {
115 $id = Auth()->user()->id; 115 $id = Auth()->user()->id;
116 $jobs = Job_title::query()->OrderBy('name')->get(); 116 $jobs = Job_title::query()->OrderBy('name')->get();
117 $categories = Category::query()->get(); 117 $categories = Category::query()->get();
118 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 118 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
119 WhereHas('users', 119 WhereHas('users',
120 function (Builder $query) use ($id) {$query->Where('id', $id); 120 function (Builder $query) use ($id) {$query->Where('id', $id);
121 })->get(); 121 })->get();
122 122
123 return view('employers.add_vacancy', compact('Employer', 'jobs' , 'categories')); 123 return view('employers.add_vacancy', compact('Employer', 'jobs' , 'categories'));
124 } 124 }
125 125
126 // Сохранение вакансии 126 // Сохранение вакансии
127 public function cabinet_vacancy_save1(VacancyRequestEdit $request) { 127 public function cabinet_vacancy_save1(VacancyRequestEdit $request) {
128 $params = $request->all(); 128 $params = $request->all();
129 $jobs['min_salary'] = $params['min_salary']; 129 $jobs['min_salary'] = $params['min_salary'];
130 $jobs['max_salary'] = $params['max_salary']; 130 $jobs['max_salary'] = $params['max_salary'];
131 $jobs['flot'] = $params['flot']; 131 $jobs['flot'] = $params['flot'];
132 $jobs['power'] = $params['power']; 132 $jobs['power'] = $params['power'];
133 $jobs['sytki'] = $params['sytki']; 133 $jobs['sytki'] = $params['sytki'];
134 $jobs['start'] = $params['start']; 134 $jobs['start'] = $params['start'];
135 $jobs['job_title_id'] = $params['job_title_id']; 135 $jobs['job_title_id'] = $params['job_title_id'];
136 $jobs['description'] = $params['description']; 136 $jobs['description'] = $params['description'];
137 $jobs['region'] = $params['city']; 137 $jobs['region'] = $params['city'];
138 $jobs['position_ship'] = $params['position_ship']; 138 $jobs['position_ship'] = $params['position_ship'];
139 unset($params['min_salary']); 139 unset($params['min_salary']);
140 unset($params['max_salary']); 140 unset($params['max_salary']);
141 unset($params['flot']); 141 unset($params['flot']);
142 unset($params['sytki']); 142 unset($params['sytki']);
143 unset($params['start']); 143 unset($params['start']);
144 unset($params['job_title_id']); 144 unset($params['job_title_id']);
145 unset($params['description']); 145 unset($params['description']);
146 146
147 $id = Ad_employer::create($params)->id; 147 $id = Ad_employer::create($params)->id;
148 $jobs['ad_employer_id'] = $id; 148 $jobs['ad_employer_id'] = $id;
149 Ad_jobs::create($jobs); 149 Ad_jobs::create($jobs);
150 return redirect()->route('employer.vacancy_list'); 150 return redirect()->route('employer.vacancy_list');
151 } 151 }
152 152
153 // Список вакансий 153 // Список вакансий
154 public function vacancy_list(Request $request) { 154 public function vacancy_list(Request $request) {
155 $id = Auth()->user()->id; 155 $id = Auth()->user()->id;
156 $Employer = Employer::query()->where('user_id', $id)->first(); 156 $Employer = Employer::query()->where('user_id', $id)->first();
157 $vacancy_list = Ad_employer::query()->where('employer_id', $Employer->id); 157 $vacancy_list = Ad_employer::query()->where('employer_id', $Employer->id);
158 158
159 if ($request->get('sort')) { 159 if ($request->get('sort')) {
160 $sort = $request->get('sort'); 160 $sort = $request->get('sort');
161 switch ($sort) { 161 switch ($sort) {
162 case 'name_up': $vacancy_list = $vacancy_list->orderBy('name')->orderBy('id'); break; 162 case 'name_up': $vacancy_list = $vacancy_list->orderBy('name')->orderBy('id'); break;
163 case 'name_down': $vacancy_list = $vacancy_list->orderByDesc('name')->orderby('id'); break; 163 case 'name_down': $vacancy_list = $vacancy_list->orderByDesc('name')->orderby('id'); break;
164 case 'created_at_up': $vacancy_list = $vacancy_list->OrderBy('created_at')->orderBy('id'); break; 164 case 'created_at_up': $vacancy_list = $vacancy_list->OrderBy('created_at')->orderBy('id'); break;
165 case 'created_at_down': $vacancy_list = $vacancy_list->orderByDesc('created_at')->orderBy('id'); break; 165 case 'created_at_down': $vacancy_list = $vacancy_list->orderByDesc('created_at')->orderBy('id'); break;
166 case 'default': $vacancy_list = $vacancy_list->orderBy('id')->orderby('updated_at'); break; 166 case 'default': $vacancy_list = $vacancy_list->orderBy('id')->orderby('updated_at'); break;
167 default: $vacancy_list = $vacancy_list->orderBy('id')->orderby('updated_at'); break; 167 default: $vacancy_list = $vacancy_list->orderBy('id')->orderby('updated_at'); break;
168 } 168 }
169 } 169 }
170 $vacancy_list = $vacancy_list->get(); 170 $vacancy_list = $vacancy_list->get();
171 171
172 //ajax 172 //ajax
173 if ($request->ajax()) { 173 if ($request->ajax()) {
174 return view('employers.ajax.list_vacancy', compact('vacancy_list', 'Employer')); 174 return view('employers.ajax.list_vacancy', compact('vacancy_list', 'Employer'));
175 } else { 175 } else {
176 return view('employers.list_vacancy', compact('vacancy_list', 'Employer')); 176 return view('employers.list_vacancy', compact('vacancy_list', 'Employer'));
177 } 177 }
178 } 178 }
179 179
180 // Карточка вакансии 180 // Карточка вакансии
181 public function vacancy_edit(Ad_employer $ad_employer) { 181 public function vacancy_edit(Ad_employer $ad_employer) {
182 $id = Auth()->user()->id; 182 $id = Auth()->user()->id;
183 $jobs = Job_title::query()->OrderBy('name')->get(); 183 $jobs = Job_title::query()->OrderBy('name')->get();
184 $categories = Category::query()->get(); 184 $categories = Category::query()->get();
185 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 185 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
186 where('user_id', $id)->first(); 186 where('user_id', $id)->first();
187 187
188 return view('employers.edit_vacancy', compact('ad_employer', 'categories','Employer', 'jobs')); 188 return view('employers.edit_vacancy', compact('ad_employer', 'categories','Employer', 'jobs'));
189 } 189 }
190 190
191 // Сохранение-редактирование записи 191 // Сохранение-редактирование записи
192 public function vacancy_save_me(VacancyRequestEdit $request, Ad_employer $ad_employer) { 192 public function vacancy_save_me(VacancyRequestEdit $request, Ad_employer $ad_employer) {
193 $all = $request->all(); 193 $all = $request->all();
194 194
195 $ad_employer->update($all); 195 $ad_employer->update($all);
196 196
197 return redirect()->route('employer.vacancy_list'); 197 return redirect()->route('employer.vacancy_list');
198 } 198 }
199 199
200 // Сохранение карточки вакансии 200 // Сохранение карточки вакансии
201 public function vacancy_save(Request $request, Ad_employer $ad_employer) { 201 public function vacancy_save(Request $request, Ad_employer $ad_employer) {
202 $all = $request->all(); 202 $all = $request->all();
203 $ad_employer->update($all); 203 $ad_employer->update($all);
204 return redirect()->route('employer.cabinet_vacancie'); 204 return redirect()->route('employer.cabinet_vacancie');
205 } 205 }
206 206
207 // Удаление карточки вакансии 207 // Удаление карточки вакансии
208 public function vacancy_delete(Ad_employer $ad_employer) { 208 public function vacancy_delete(Ad_employer $ad_employer) {
209 $ad_employer->delete(); 209 $ad_employer->delete();
210 210
211 return redirect()->route('employer.vacancy_list') 211 return redirect()->route('employer.vacancy_list')
212 ->with('success', 'Данные были успешно сохранены'); 212 ->with('success', 'Данные были успешно сохранены');
213 } 213 }
214 214
215 // Обновление даты 215 // Обновление даты
216 public function vacancy_up(Ad_employer $ad_employer) { 216 public function vacancy_up(Ad_employer $ad_employer) {
217 $up = date('m/d/Y h:i:s', time());; 217 $up = date('m/d/Y h:i:s', time());;
218 $vac_emp = Ad_employer::findOrFail($ad_employer->id); 218 $vac_emp = Ad_employer::findOrFail($ad_employer->id);
219 $vac_emp->updated_at = $up; 219 $vac_emp->updated_at = $up;
220 $vac_emp->save(); 220 $vac_emp->save();
221 221
222 return redirect()->route('employer.vacancy_list'); 222 return redirect()->route('employer.vacancy_list');
223 // начало конца 223 // начало конца
224 } 224 }
225 225
226 //Видимость вакансии 226 //Видимость вакансии
227 public function vacancy_eye(Ad_employer $ad_employer, $status) { 227 public function vacancy_eye(Ad_employer $ad_employer, $status) {
228 $vac_emp = Ad_employer::findOrFail($ad_employer->id); 228 $vac_emp = Ad_employer::findOrFail($ad_employer->id);
229 $vac_emp->active_is = $status; 229 $vac_emp->active_is = $status;
230 $vac_emp->save(); 230 $vac_emp->save();
231 231
232 return redirect()->route('employer.vacancy_list'); 232 return redirect()->route('employer.vacancy_list');
233 } 233 }
234 234
235 //Вакансия редактирования (шаблон) 235 //Вакансия редактирования (шаблон)
236 public function vacancy_update(Ad_employer $id) { 236 public function vacancy_update(Ad_employer $id) {
237 237
238 } 238 }
239 239
240 //Отклики на вакансию - лист 240 //Отклики на вакансию - лист
241 public function answers(Employer $employer, Request $request) { 241 public function answers(Employer $employer, Request $request) {
242 $user_id = Auth()->user()->id; 242 $user_id = Auth()->user()->id;
243 $answer = Ad_employer::query()->where('employer_id', $employer->id); 243 $answer = Ad_employer::query()->where('employer_id', $employer->id);
244 if ($request->has('search')) { 244 if ($request->has('search')) {
245 $search = trim($request->get('search')); 245 $search = trim($request->get('search'));
246 if (!empty($search)) $answer = $answer->where('name', 'LIKE', "%$search%"); 246 if (!empty($search)) $answer = $answer->where('name', 'LIKE', "%$search%");
247 } 247 }
248 248
249 $answer = $answer->with('response')->get(); 249 $answer = $answer->with('response')->get();
250 250
251 return view('employers.list_answer', compact('answer', 'user_id', 'employer')); 251 return view('employers.list_answer', compact('answer', 'user_id', 'employer'));
252 } 252 }
253 253
254 //Обновление статуса 254 //Обновление статуса
255 public function supple_status(employer $employer, ad_response $ad_response, $flag) { 255 public function supple_status(employer $employer, ad_response $ad_response, $flag) {
256 $ad_response->update(Array('flag' => $flag)); 256 $ad_response->update(Array('flag' => $flag));
257 return redirect()->route('employer.answers', ['employer' => $employer->id]); 257 return redirect()->route('employer.answers', ['employer' => $employer->id]);
258 } 258 }
259 259
260 //Страницы сообщений список 260 //Страницы сообщений список
261 public function messages($type_message) { 261 public function messages($type_message) {
262 $user_id = Auth()->user()->id; 262 $user_id = Auth()->user()->id;
263 263
264 $messages_input = Message::query()->with('vacancies')->with('user_from')-> 264 $messages_input = Message::query()->with('vacancies')->with('user_from')->
265 Where('to_user_id', $user_id)->OrderByDesc('created_at'); 265 Where('to_user_id', $user_id)->OrderByDesc('created_at');
266 266
267 $messages_output = Message::query()->with('vacancies')-> 267 $messages_output = Message::query()->with('vacancies')->
268 with('user_to')->where('user_id', $user_id)-> 268 with('user_to')->where('user_id', $user_id)->
269 OrderByDesc('created_at'); 269 OrderByDesc('created_at');
270 270
271 271
272 $count_input = $messages_input->count(); 272 $count_input = $messages_input->count();
273 $count_output = $messages_output->count(); 273 $count_output = $messages_output->count();
274 274
275 if ($type_message == 'input') { 275 if ($type_message == 'input') {
276 $messages = $messages_input->paginate(15); 276 $messages = $messages_input->paginate(15);
277 } 277 }
278 278
279 if ($type_message == 'output') { 279 if ($type_message == 'output') {
280 $messages = $messages_output->paginate(15); 280 $messages = $messages_output->paginate(15);
281 } 281 }
282 282
283 return view('employers.messages', compact('messages', 'count_input', 'count_output', 'type_message', 'user_id')); 283 return view('employers.messages', compact('messages', 'count_input', 'count_output', 'type_message', 'user_id'));
284 } 284 }
285 285
286 // Диалог между пользователями 286 // Диалог между пользователями
287 public function dialog(User_Model $user1, User_Model $user2) { 287 public function dialog(User_Model $user1, User_Model $user2) {
288 if (isset($user2->id)) { 288 if (isset($user2->id)) {
289 $companion = User_Model::query()->with('workers')-> 289 $companion = User_Model::query()->with('workers')->
290 with('employers')-> 290 with('employers')->
291 where('id', $user2->id)->first(); 291 where('id', $user2->id)->first();
292 } 292 }
293 293
294 $Messages = Message::query()->with('response')->where(function($query) use ($user1, $user2) { 294 $Messages = Message::query()->with('response')->where(function($query) use ($user1, $user2) {
295 $query->where('user_id', $user1->id)->where('to_user_id', $user2->id); 295 $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
296 })->orWhere(function($query) use ($user1, $user2) { 296 })->orWhere(function($query) use ($user1, $user2) {
297 $query->where('user_id', $user2->id)->where('to_user_id', $user1->id); 297 $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
298 })->OrderBy('created_at')->get(); 298 })->OrderBy('created_at')->get();
299 299
300 $id_vac = null; 300 $id_vac = null;
301 foreach ($Messages as $it) { 301 foreach ($Messages as $it) {
302 if (isset($it->response)) { 302 if (isset($it->response)) {
303 foreach ($it->response as $r) { 303 foreach ($it->response as $r) {
304 if (isset($r->ad_employer_id)) { 304 if (isset($r->ad_employer_id)) {
305 $id_vac = $r->ad_employer_id; 305 $id_vac = $r->ad_employer_id;
306 break; 306 break;
307 } 307 }
308 } 308 }
309 } 309 }
310 if (!is_null($id_vac)) break; 310 if (!is_null($id_vac)) break;
311 } 311 }
312 312
313 $ad_employer = null; 313 $ad_employer = null;
314 if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first(); 314 if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first();
315 $sender = $user1; 315 $sender = $user1;
316 316
317 return view('employers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer')); 317 return view('employers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer'));
318 } 318 }
319 319
320 // Регистрация работодателя 320 // Регистрация работодателя
321 public function register_employer(Request $request) { 321 public function register_employer(Request $request) {
322 $params = $request->all(); 322 $params = $request->all();
323 323
324 $rules = [ 324 $rules = [
325 'surname' => ['required', 'string', 'max:255'], 325 'surname' => ['required', 'string', 'max:255'],
326 'name_man' => ['required', 'string', 'max:255'], 326 'name_man' => ['required', 'string', 'max:255'],
327 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 327 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
328 'name_company' => ['required', 'string', 'max:255'], 328 'name_company' => ['required', 'string', 'max:255'],
329 'password' => ['required', 'string', 'min:8'], 329 'password' => ['required', 'string', 'min:8'],
330 ]; 330 ];
331 331
332 332
333 $messages = [ 333 $messages = [
334 'required' => 'Укажите обязательное поле', 334 'required' => 'Укажите обязательное поле',
335 'min' => [ 335 'min' => [
336 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 336 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
337 'integer' => 'Поле «:attribute» должно быть :min или больше', 337 'integer' => 'Поле «:attribute» должно быть :min или больше',
338 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 338 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
339 ], 339 ],
340 'max' => [ 340 'max' => [
341 'string' => 'Поле «:attribute» должно быть не больше :max символов', 341 'string' => 'Поле «:attribute» должно быть не больше :max символов',
342 'integer' => 'Поле «:attribute» должно быть :max или меньше', 342 'integer' => 'Поле «:attribute» должно быть :max или меньше',
343 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 343 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
344 ] 344 ]
345 ]; 345 ];
346 346
347 if ($request->get('password') !== $request->get('confirmed')){ 347 if ($request->get('password') !== $request->get('confirmed')){
348 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); 348 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля"));
349 } 349 }
350 350
351 $validator = Validator::make($request->all(), $rules, $messages); 351 $validator = Validator::make($request->all(), $rules, $messages);
352 352
353 if ($validator->fails()) { 353 if ($validator->fails()) {
354 return json_encode(Array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); 354 return json_encode(Array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе."));
355 } else { 355 } else {
356 $user = $this->create($params); 356 $user = $this->create($params);
357 event(new Registered($user)); 357 event(new Registered($user));
358 358
359 Auth::guard()->login($user); 359 Auth::guard()->login($user);
360 } 360 }
361 if ($user) { 361 if ($user) {
362 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));; 362 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));;
363 } else { 363 } else {
364 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!")); 364 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!"));
365 } 365 }
366 } 366 }
367 367
368 // Создание пользователя 368 // Создание пользователя
369 protected function create(array $data) 369 protected function create(array $data)
370 { 370 {
371 $Use = new User_Model(); 371 $Use = new User_Model();
372 $Code_user = $Use->create([ 372 $Code_user = $Use->create([
373 'name' => $data['surname']." ".$data['name_man'], 373 'name' => $data['surname']." ".$data['name_man'],
374 'name_man' => $data['name_man'], 374 'name_man' => $data['name_man'],
375 'surname' => $data['surname'], 375 'surname' => $data['surname'],
376 'surname2' => $data['surname2'], 376 'surname2' => $data['surname2'],
377 'subscribe_email' => $data['email'], 377 'subscribe_email' => $data['email'],
378 'email' => $data['email'], 378 'email' => $data['email'],
379 'telephone' => $data['telephone'], 379 'telephone' => $data['telephone'],
380 'is_worker' => 0, 380 'is_worker' => 0,
381 'password' => Hash::make($data['password']), 381 'password' => Hash::make($data['password']),
382 'pubpassword' => base64_encode($data['password']), 382 'pubpassword' => base64_encode($data['password']),
383 'email_verified_at' => Carbon::now() 383 'email_verified_at' => Carbon::now()
384 ]); 384 ]);
385 385
386 if ($Code_user->id > 0) { 386 if ($Code_user->id > 0) {
387 $Employer = new Employer(); 387 $Employer = new Employer();
388 $Employer->user_id = $Code_user->id; 388 $Employer->user_id = $Code_user->id;
389 $Employer->name_company = $data['name_company']; 389 $Employer->name_company = $data['name_company'];
390 $Employer->email = $data['email']; 390 $Employer->email = $data['email'];
391 $Employer->telephone = $data['telephone']; 391 $Employer->telephone = $data['telephone'];
392 $Employer->code = Tools::generator_id(10); 392 $Employer->code = Tools::generator_id(10);
393 $Employer->save(); 393 $Employer->save();
394 394
395 return $Code_user; 395 return $Code_user;
396 } 396 }
397 } 397 }
398 398
399 // Отправка сообщения от работодателя 399 // Отправка сообщения от работодателя
400 public function send_message(MessagesRequiest $request) { 400 public function send_message(MessagesRequiest $request) {
401 $params = $request->all(); 401 $params = $request->all();
402 dd($params); 402 dd($params);
403 $user1 = $params['user_id']; 403 $user1 = $params['user_id'];
404 $user2 = $params['to_user_id']; 404 $user2 = $params['to_user_id'];
405 405
406 if ($request->has('file')) { 406 if ($request->has('file')) {
407 $params['file'] = $request->file('file')->store("messages", 'public'); 407 $params['file'] = $request->file('file')->store("messages", 'public');
408 } 408 }
409 Message::create($params); 409 Message::create($params);
410 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 410 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
411 } 411 }
412 412
413 public function test123(Request $request) { 413 public function test123(Request $request) {
414 $params = $request->all(); 414 $params = $request->all();
415 $user1 = $params['user_id']; 415 $user1 = $params['user_id'];
416 $user2 = $params['to_user_id']; 416 $user2 = $params['to_user_id'];
417 417
418 $rules = [ 418 $rules = [
419 'text' => 'required|min:1|max:150000', 419 'text' => 'required|min:1|max:150000',
420 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' 420 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000'
421 ]; 421 ];
422 $messages = [ 422 $messages = [
423 'required' => 'Укажите обязательное поле', 423 'required' => 'Укажите обязательное поле',
424 'min' => [ 424 'min' => [
425 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 425 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
426 'integer' => 'Поле «:attribute» должно быть :min или больше', 426 'integer' => 'Поле «:attribute» должно быть :min или больше',
427 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 427 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
428 ], 428 ],
429 'max' => [ 429 'max' => [
430 'string' => 'Поле «:attribute» должно быть не больше :max символов', 430 'string' => 'Поле «:attribute» должно быть не больше :max символов',
431 'integer' => 'Поле «:attribute» должно быть :max или меньше', 431 'integer' => 'Поле «:attribute» должно быть :max или меньше',
432 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 432 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
433 ] 433 ]
434 ]; 434 ];
435 435
436 $validator = Validator::make($request->all(), $rules, $messages); 436 $validator = Validator::make($request->all(), $rules, $messages);
437 437
438 if ($validator->fails()) { 438 if ($validator->fails()) {
439 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]) 439 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2])
440 ->withErrors($validator); 440 ->withErrors($validator);
441 } else { 441 } else {
442 if ($request->has('file')) { 442 if ($request->has('file')) {
443 $params['file'] = $request->file('file')->store("messages", 'public'); 443 $params['file'] = $request->file('file')->store("messages", 'public');
444 } 444 }
445 Message::create($params); 445 Message::create($params);
446 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 446 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
447 447
448 } 448 }
449 } 449 }
450 450
451 //Избранные люди 451 //Избранные люди
452 public function favorites(Request $request) { 452 public function favorites(Request $request) {
453 $IP_address = RusDate::ip_addr_client(); 453 $IP_address = RusDate::ip_addr_client();
454 $Arr = Like_worker::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get(); 454 $Arr = Like_worker::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get();
455 455
456 if ($Arr->count()) { 456 if ($Arr->count()) {
457 $A = Array(); 457 $A = Array();
458 foreach ($Arr as $it) { 458 foreach ($Arr as $it) {
459 $A[] = $it->code_record; 459 $A[] = $it->code_record;
460 } 460 }
461 461
462 $Workers = Worker::query()->whereIn('id', $A); 462 $Workers = Worker::query()->whereIn('id', $A);
463 } else { 463 } else {
464 $Workers = Worker::query(); 464 $Workers = Worker::query()->where('id', '=', '0');
465 } 465 }
466 466
467 if (($request->has('search')) && (!empty($request->get('search')))) { 467 if (($request->has('search')) && (!empty($request->get('search')))) {
468 $search = $request->get('search'); 468 $search = $request->get('search');
469 469
470 $Workers = $Workers->WhereHas('users', 470 $Workers = $Workers->WhereHas('users',
471 function (Builder $query) use ($search) { 471 function (Builder $query) use ($search) {
472 $query->Where('surname', 'LIKE', "%$search%") 472 $query->Where('surname', 'LIKE', "%$search%")
473 ->orWhere('name_man', 'LIKE', "%$search%") 473 ->orWhere('name_man', 'LIKE', "%$search%")
474 ->orWhere('surname2', 'LIKE', "%$search%"); 474 ->orWhere('surname2', 'LIKE', "%$search%");
475 }); 475 });
476 } else { 476 } else {
477 $Workers = $Workers->with('users'); 477 $Workers = $Workers->with('users');
478 } 478 }
479 479
480 $Workers = $Workers->get(); 480 $Workers = $Workers->get();
481 return view('employers.favorite', compact('Workers')); 481 return view('employers.favorite', compact('Workers'));
482 } 482 }
483 483
484 // База данных 484 // База данных
485 public function bd(Request $request) { 485 public function bd(Request $request) {
486 // для типа BelongsTo 486 // для типа BelongsTo
487 //$documents = Document::query()->orderBy(Location::select('name') 487 //$documents = Document::query()->orderBy(Location::select('name')
488 // ->whereColumn('locations.id', 'documents.location_id') 488 // ->whereColumn('locations.id', 'documents.location_id')
489 //); 489 //);
490 490
491 // для типа HasOne/Many 491 // для типа HasOne/Many
492 // $documents = Document::::query()->orderBy(Location::select('name') 492 // $documents = Document::::query()->orderBy(Location::select('name')
493 // ->whereColumn('locations.document_id', 'documents.id') 493 // ->whereColumn('locations.document_id', 'documents.id')
494 //); 494 //);
495 495
496 $users = User_Model::query()->with('workers'); 496 $users = User_Model::query()->with('workers');
497 if (isset($request->find)) { 497 if (isset($request->find)) {
498 $find_key = $request->find; 498 $find_key = $request->find;
499 $users = $users->where('name', 'LIKE', "%$find_key%") 499 $users = $users->where('name', 'LIKE', "%$find_key%")
500 ->orWhere('email', 'LIKE', "%$find_key%") 500 ->orWhere('email', 'LIKE', "%$find_key%")
501 ->orWhere('telephone', 'LIKE', "%$find_key%"); 501 ->orWhere('telephone', 'LIKE', "%$find_key%");
502 } 502 }
503 503
504 // Данные 504 // Данные
505 $users = $users->Baseuser()-> 505 $users = $users->Baseuser()->
506 orderBy(Worker::select('position_work')->whereColumn('Workers.user_id', 'users.id'))-> 506 orderBy(Worker::select('position_work')->whereColumn('Workers.user_id', 'users.id'))->
507 paginate(5); 507 paginate(5);
508 508
509 return view('employers.bd', compact('users')); 509 return view('employers.bd', compact('users'));
510 } 510 }
511 511
512 //Настройка уведомлений 512 //Настройка уведомлений
513 public function subscribe() { 513 public function subscribe() {
514 return view('employers.subcribe'); 514 return view('employers.subcribe');
515 } 515 }
516 516
517 //Установка уведомлений сохранение 517 //Установка уведомлений сохранение
518 public function save_subscribe(Request $request) { 518 public function save_subscribe(Request $request) {
519 dd($request->all()); 519 dd($request->all());
520 $msg = $request->validate([ 520 $msg = $request->validate([
521 'subscribe_email' => 'required|email|min:5|max:255', 521 'subscribe_email' => 'required|email|min:5|max:255',
522 ]); 522 ]);
523 return redirect()->route('employer.subscribe')->with('Вы успешно подписались на рассылку'); 523 return redirect()->route('employer.subscribe')->with('Вы успешно подписались на рассылку');
524 } 524 }
525 525
526 //Сбросить форму с паролем 526 //Сбросить форму с паролем
527 public function password_reset() { 527 public function password_reset() {
528 $email = Auth()->user()->email; 528 $email = Auth()->user()->email;
529 return view('employers.password-reset', compact('email')); 529 return view('employers.password-reset', compact('email'));
530 } 530 }
531 531
532 //Обновление пароля 532 //Обновление пароля
533 public function new_password(Request $request) { 533 public function new_password(Request $request) {
534 $use = Auth()->user(); 534 $use = Auth()->user();
535 $request->validate([ 535 $request->validate([
536 'password' => 'required|string', 536 'password' => 'required|string',
537 'new_password' => 'required|string', 537 'new_password' => 'required|string',
538 'new_password2' => 'required|string' 538 'new_password2' => 'required|string'
539 ]); 539 ]);
540 540
541 if ($request->get('new_password') == $request->get('new_password2')) 541 if ($request->get('new_password') == $request->get('new_password2'))
542 if ($request->get('password') !== $request->get('new_password')) { 542 if ($request->get('password') !== $request->get('new_password')) {
543 $credentials = $request->only('email', 'password'); 543 $credentials = $request->only('email', 'password');
544 if (Auth::attempt($credentials)) { 544 if (Auth::attempt($credentials)) {
545 545
546 if (!is_null($use->email_verified_at)){ 546 if (!is_null($use->email_verified_at)){
547 547
548 $user_data = User_Model::find($use->id); 548 $user_data = User_Model::find($use->id);
549 $user_data->update([ 549 $user_data->update([
550 'password' => Hash::make($request->get('new_password')), 550 'password' => Hash::make($request->get('new_password')),
551 'pubpassword' => base64_encode($request->get('new_password')), 551 'pubpassword' => base64_encode($request->get('new_password')),
552 ]); 552 ]);
553 return redirect() 553 return redirect()
554 ->route('employer.password_reset') 554 ->route('employer.password_reset')
555 ->with('success', 'Поздравляю! Вы обновили свой пароль!'); 555 ->with('success', 'Поздравляю! Вы обновили свой пароль!');
556 } 556 }
557 557
558 return redirect() 558 return redirect()
559 ->route('employer.password_reset') 559 ->route('employer.password_reset')
560 ->withError('Данная учетная запись не было верифицированна!'); 560 ->withError('Данная учетная запись не было верифицированна!');
561 } 561 }
562 } 562 }
563 563
564 return redirect() 564 return redirect()
565 ->route('employer.password_reset') 565 ->route('employer.password_reset')
566 ->withErrors('Не совпадение данных, обновите пароли!'); 566 ->withErrors('Не совпадение данных, обновите пароли!');
567 } 567 }
568 568
569 569
570 570
571 // Форма Удаление пипла 571 // Форма Удаление пипла
572 public function delete_people() { 572 public function delete_people() {
573 $login = Auth()->user()->email; 573 $login = Auth()->user()->email;
574 return view('employers.delete_people', compact('login')); 574 return view('employers.delete_people', compact('login'));
575 } 575 }
576 576
577 // Удаление аккаунта 577 // Удаление аккаунта
578 public function action_delete_user(Request $request) { 578 public function action_delete_user(Request $request) {
579 $Answer = $request->all(); 579 $Answer = $request->all();
580 $user_id = Auth()->user()->id; 580 $user_id = Auth()->user()->id;
581 $request->validate([ 581 $request->validate([
582 'password' => 'required|string', 582 'password' => 'required|string',
583 ]); 583 ]);
584 584
585 $credentials = $request->only('email', 'password'); 585 $credentials = $request->only('email', 'password');
586 if (Auth::attempt($credentials)) { 586 if (Auth::attempt($credentials)) {
587 Auth::logout(); 587 Auth::logout();
588 $it = User_Model::find($user_id); 588 $it = User_Model::find($user_id);
589 $it->delete(); 589 $it->delete();
590 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); 590 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
591 } else { 591 } else {
592 return redirect()->route('employer.delete_people') 592 return redirect()->route('employer.delete_people')
593 ->withErrors( 'Неверный пароль! Нужен корректный пароль'); 593 ->withErrors( 'Неверный пароль! Нужен корректный пароль');
594 } 594 }
595 } 595 }
596 596
597 public function ajax_delete_user(Request $request) { 597 public function ajax_delete_user(Request $request) {
598 $Answer = $request->all(); 598 $Answer = $request->all();
599 $user_id = Auth()->user()->id; 599 $user_id = Auth()->user()->id;
600 $request->validate([ 600 $request->validate([
601 'password' => 'required|string', 601 'password' => 'required|string',
602 ]); 602 ]);
603 $credentials = $request->only('email', 'password'); 603 $credentials = $request->only('email', 'password');
604 if (Auth::attempt($credentials)) { 604 if (Auth::attempt($credentials)) {
605 605
606 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт', 606 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт',
607 'email' => $request->get('email'), 607 'email' => $request->get('email'),
608 'password' => $request->get('password'))); 608 'password' => $request->get('password')));
609 } else { 609 } else {
610 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль')); 610 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль'));
611 } 611 }
612 } 612 }
613 613
614 614
615 // FAQ - Вопросы/ответы для работодателей и соискателей 615 // FAQ - Вопросы/ответы для работодателей и соискателей
616 public function faq() { 616 public function faq() {
617 return view('employers.faq'); 617 return view('employers.faq');
618 } 618 }
619 619
620 // Рассылка сообщений 620 // Рассылка сообщений
621 public function send_all_messages() { 621 public function send_all_messages() {
622 return view('employers.send_all'); 622 return view('employers.send_all');
623 } 623 }
624 624
625 // Отправка сообщений для информации 625 // Отправка сообщений для информации
626 public function send_all_post(Request $request) { 626 public function send_all_post(Request $request) {
627 $data = $request->all(); 627 $data = $request->all();
628 628
629 $emails = User_Model::query()->where('is_worker', '1')->get(); 629 $emails = User_Model::query()->where('is_worker', '1')->get();
630 630
631 foreach ($emails as $e) { 631 foreach ($emails as $e) {
632 Mail::to($e->email)->send(new SendAllMessages($data)); 632 Mail::to($e->email)->send(new SendAllMessages($data));
633 } 633 }
634 634
635 return redirect()->route('employer.send_all_messages')->with('success', 'Письма были отправлены'); 635 return redirect()->route('employer.send_all_messages')->with('success', 'Письма были отправлены');
636 } 636 }
637 637
638 // База резюме 638 // База резюме
639 public function bd_tupe(Request $request) { 639 public function bd_tupe(Request $request) {
640 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get(); 640 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get();
641 641
642 return view('employers.bd_tupe', compact('Resume')); 642 return view('employers.bd_tupe', compact('Resume'));
643 } 643 }
644 644
645 ////////////////////////////////////////////////////////////////// 645 //////////////////////////////////////////////////////////////////
646 // 646 //
647 // 647 //
648 // Отправил сообщение 648 // Отправил сообщение
649 // 649 //
650 // 650 //
651 // 651 //
652 // 652 //
653 ////////////////////////////////////////////////////////////////// 653 //////////////////////////////////////////////////////////////////
654 public function new_message(Request $request) { 654 public function new_message(Request $request) {
655 $params = $request->all(); 655 $params = $request->all();
656 656
657 $id = $params['_user_id']; 657 $id = $params['_user_id'];
658 $message = new Message(); 658 $message = new Message();
659 $message->user_id = $params['_user_id']; 659 $message->user_id = $params['_user_id'];
660 $message->to_user_id = $params['_to_user_id']; 660 $message->to_user_id = $params['_to_user_id'];
661 $message->title = $params['title']; 661 $message->title = $params['title'];
662 $message->text = $params['text']; 662 $message->text = $params['text'];
663 if ($request->has('_file')) { 663 if ($request->has('_file')) {
664 $message->file = $request->file('_file')->store("worker/$id", 'public'); 664 $message->file = $request->file('_file')->store("worker/$id", 'public');
665 } 665 }
666 $message->flag_new = 1; 666 $message->flag_new = 1;
667 $id_message = $message->save(); 667 $id_message = $message->save();
668 668
669 $data['message_id'] = $id_message; 669 $data['message_id'] = $id_message;
670 $data['ad_employer_id'] = $params['_vacancy']; 670 $data['ad_employer_id'] = $params['_vacancy'];
671 $data['job_title_id'] = 0; 671 $data['job_title_id'] = 0;
672 672
673 $data['flag'] = 1; 673 $data['flag'] = 1;
674 $ad_responce = ad_response::create($data); 674 $ad_responce = ad_response::create($data);
675 return redirect()->route('employer.messages', ['type_message' => 'output']); 675 return redirect()->route('employer.messages', ['type_message' => 'output']);
676 } 676 }
677 677
678 // Восстановление пароля 678 // Восстановление пароля
679 public function repair_password(Request $request) { 679 public function repair_password(Request $request) {
680 $params = $request->get('email'); 680 $params = $request->get('email');
681 681
682 682
683 } 683 }
684 } 684 }
685 685
app/Http/Controllers/WorkerController.php
1 <?php 1 <?php
2 2
3 namespace App\Http\Controllers; 3 namespace App\Http\Controllers;
4 4
5 use App\Classes\RusDate; 5 use App\Classes\RusDate;
6 use App\Http\Requests\DocumentsRequest; 6 use App\Http\Requests\DocumentsRequest;
7 use App\Models\Ad_employer; 7 use App\Models\Ad_employer;
8 use App\Models\ad_response; 8 use App\Models\ad_response;
9 use App\Models\Category; 9 use App\Models\Category;
10 use App\Models\Dop_info; 10 use App\Models\Dop_info;
11 use App\Models\Employer; 11 use App\Models\Employer;
12 use App\Models\infobloks; 12 use App\Models\infobloks;
13 use App\Models\Job_title; 13 use App\Models\Job_title;
14 use App\Models\Like_vacancy; 14 use App\Models\Like_vacancy;
15 use App\Models\Like_worker; 15 use App\Models\Like_worker;
16 use App\Models\Message; 16 use App\Models\Message;
17 use App\Models\place_works; 17 use App\Models\place_works;
18 use App\Models\reclame; 18 use App\Models\reclame;
19 use App\Models\ResponseWork; 19 use App\Models\ResponseWork;
20 use App\Models\sertification; 20 use App\Models\sertification;
21 use App\Models\Static_worker; 21 use App\Models\Static_worker;
22 use App\Models\User; 22 use App\Models\User;
23 use App\Models\User as User_Model; 23 use App\Models\User as User_Model;
24 use App\Models\Worker; 24 use App\Models\Worker;
25 use Barryvdh\DomPDF\Facade\Pdf; 25 use Barryvdh\DomPDF\Facade\Pdf;
26 use Carbon\Carbon; 26 use Carbon\Carbon;
27 use Illuminate\Auth\Events\Registered; 27 use Illuminate\Auth\Events\Registered;
28 use Illuminate\Database\Eloquent\Builder; 28 use Illuminate\Database\Eloquent\Builder;
29 use Illuminate\Database\Eloquent\Model; 29 use Illuminate\Database\Eloquent\Model;
30 use Illuminate\Http\JsonResponse; 30 use Illuminate\Http\JsonResponse;
31 use Illuminate\Http\Request; 31 use Illuminate\Http\Request;
32 use Illuminate\Support\Facades\Auth; 32 use Illuminate\Support\Facades\Auth;
33 use Illuminate\Support\Facades\Hash; 33 use Illuminate\Support\Facades\Hash;
34 use Illuminate\Support\Facades\Storage; 34 use Illuminate\Support\Facades\Storage;
35 use Illuminate\Support\Facades\Validator; 35 use Illuminate\Support\Facades\Validator;
36 36
37 class WorkerController extends Controller 37 class WorkerController extends Controller
38 { 38 {
39 public $status_work = array(0 => 'Ищу работу', 1 => 'Не указано', 2 => 'Не ищу работу'); 39 public $status_work = array(0 => 'Ищу работу', 1 => 'Не указано', 2 => 'Не ищу работу');
40 40
41 //профиль 41 //профиль
42 public function profile(Worker $worker) 42 public function profile(Worker $worker)
43 { 43 {
44 $get_date = date('Y.m'); 44 $get_date = date('Y.m');
45 45
46 $c = Static_worker::query()->where('year_month', '=', $get_date) 46 $c = Static_worker::query()->where('year_month', '=', $get_date)
47 ->where('user_id', '=', $worker->users->id) 47 ->where('user_id', '=', $worker->users->id)
48 ->get(); 48 ->get();
49 49
50 if ($c->count() > 0) { 50 if ($c->count() > 0) {
51 $upd = Static_worker::find($c[0]->id); 51 $upd = Static_worker::find($c[0]->id);
52 $upd->lookin = $upd->lookin + 1; 52 $upd->lookin = $upd->lookin + 1;
53 $upd->save(); 53 $upd->save();
54 } else { 54 } else {
55 $crt = new Static_worker(); 55 $crt = new Static_worker();
56 $crt->lookin = 1; 56 $crt->lookin = 1;
57 $crt->year_month = $get_date; 57 $crt->year_month = $get_date;
58 $crt->user_id = $worker->user_id; 58 $crt->user_id = $worker->user_id;
59 $crt->save(); 59 $crt->save();
60 } 60 }
61 61
62 $stat = Static_worker::query()->where('year_month', '=', $get_date) 62 $stat = Static_worker::query()->where('year_month', '=', $get_date)
63 ->where('user_id', '=', $worker->users->id) 63 ->where('user_id', '=', $worker->users->id)
64 ->get(); 64 ->get();
65 65
66 return view('public.workers.profile', compact('worker', 'stat')); 66 return view('public.workers.profile', compact('worker', 'stat'));
67 } 67 }
68 68
69 // лист база резюме 69 // лист база резюме
70 public function bd_resume(Request $request) 70 public function bd_resume(Request $request)
71 { 71 {
72 if (isset(Auth()->user()->id)) { 72 if (isset(Auth()->user()->id)) {
73 $idiot = Auth()->user()->id; 73 $idiot = Auth()->user()->id;
74 } else { 74 } else {
75 $idiot = 0; 75 $idiot = 0;
76 } 76 }
77 77
78 $status_work = $this->status_work; 78 $status_work = $this->status_work;
79 $resumes = Worker::query()->with('users')->with('job_titles'); 79 $resumes = Worker::query()->with('users')->with('job_titles');
80 $resumes = $resumes->whereHas('users', function (Builder $query) { 80 $resumes = $resumes->whereHas('users', function (Builder $query) {
81 $query->Where('is_worker', '=', '1') 81 $query->Where('is_worker', '=', '1')
82 ->Where('is_bd', '=', '0'); 82 ->Where('is_bd', '=', '0');
83 }); 83 });
84 84
85 if ($request->get('sort')) { 85 if ($request->get('sort')) {
86 $sort = $request->get('sort'); 86 $sort = $request->get('sort');
87 switch ($sort) { 87 switch ($sort) {
88 case 'name_up': 88 case 'name_up':
89 $resumes = $resumes->orderBy(User::select('surname') 89 $resumes = $resumes->orderBy(User::select('surname')
90 ->whereColumn('Workers.user_id', 'users.id') 90 ->whereColumn('Workers.user_id', 'users.id')
91 ); 91 );
92 break; 92 break;
93 case 'name_down': 93 case 'name_down':
94 $resumes = $resumes->orderByDesc(User::select('surname') 94 $resumes = $resumes->orderByDesc(User::select('surname')
95 ->whereColumn('Workers.user_id', 'users.id') 95 ->whereColumn('Workers.user_id', 'users.id')
96 ); 96 );
97 break; 97 break;
98 case 'created_at_up': $resumes = $resumes->OrderBy('created_at')->orderBy('id'); break; 98 case 'created_at_up': $resumes = $resumes->OrderBy('created_at')->orderBy('id'); break;
99 case 'created_at_down': $resumes = $resumes->orderByDesc('created_at')->orderBy('id'); break; 99 case 'created_at_down': $resumes = $resumes->orderByDesc('created_at')->orderBy('id'); break;
100 case 'default': $resumes = $resumes->orderBy('id')->orderby('updated_at'); break; 100 case 'default': $resumes = $resumes->orderBy('id')->orderby('updated_at'); break;
101 default: $resumes = $resumes->orderBy('id')->orderby('updated_at'); break; 101 default: $resumes = $resumes->orderBy('id')->orderby('updated_at'); break;
102 } 102 }
103 } 103 }
104 104
105 $res_count = $resumes->count(); 105 $res_count = $resumes->count();
106 $resumes = $resumes->paginate(6); 106 $resumes = $resumes->paginate(6);
107 if ($request->ajax()) { 107 if ($request->ajax()) {
108 // Условия обставлены 108 // Условия обставлены
109 if ($request->has('block') && ($request->get('block') == 1)) { 109 if ($request->has('block') && ($request->get('block') == 1)) {
110 return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count', 'idiot')); 110 return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count', 'idiot'));
111 } 111 }
112 112
113 if ($request->has('block') && ($request->get('block') == 2)) { 113 if ($request->has('block') && ($request->get('block') == 2)) {
114 return view('ajax.resume_2', compact('resumes', 'status_work', 'res_count', 'idiot')); 114 return view('ajax.resume_2', compact('resumes', 'status_work', 'res_count', 'idiot'));
115 } 115 }
116 } else { 116 } else {
117 return view('resume', compact('resumes', 'status_work', 'res_count', 'idiot')); 117 return view('resume', compact('resumes', 'status_work', 'res_count', 'idiot'));
118 } 118 }
119 } 119 }
120 120
121 //Лайк резюме 121 //Лайк резюме
122 public function like_controller() { 122 public function like_controller() {
123 123
124 } 124 }
125 125
126 // анкета соискателя 126 // анкета соискателя
127 public function resume_profile(Worker $worker) 127 public function resume_profile(Worker $worker)
128 { 128 {
129 $status_work = $this->status_work; 129 $status_work = $this->status_work;
130 $Query = Worker::query()->with('users')->with('job_titles') 130 $Query = Worker::query()->with('users')->with('job_titles')
131 ->with('place_worker')->with('sertificate')->with('prev_company') 131 ->with('place_worker')->with('sertificate')->with('prev_company')
132 ->with('infobloks'); 132 ->with('infobloks');
133 $Query = $Query->where('id', '=', $worker->id); 133 $Query = $Query->where('id', '=', $worker->id);
134 $Query = $Query->get(); 134 $Query = $Query->get();
135 135
136 $get_date = date('Y.m'); 136 $get_date = date('Y.m');
137 $c = Static_worker::query()->where('year_month', '=', $get_date) 137 $c = Static_worker::query()->where('year_month', '=', $get_date)
138 ->where('user_id', '=', $worker->id) 138 ->where('user_id', '=', $worker->id)
139 ->get(); 139 ->get();
140 140
141 if ($c->count() > 0) { 141 if ($c->count() > 0) {
142 $upd = Static_worker::find($c[0]->id); 142 $upd = Static_worker::find($c[0]->id);
143 $upd->lookin = $upd->lookin + 1; 143 $upd->lookin = $upd->lookin + 1;
144 $upd->save(); 144 $upd->save();
145 } else { 145 } else {
146 $crt = new Static_worker(); 146 $crt = new Static_worker();
147 $crt->lookin = 1; 147 $crt->lookin = 1;
148 $crt->year_month = $get_date; 148 $crt->year_month = $get_date;
149 $crt->user_id = $worker->user_id; 149 $crt->user_id = $worker->user_id;
150 $crt->save(); 150 $crt->save();
151 } 151 }
152 152
153 $stat = Static_worker::query()->where('year_month', '=', $get_date) 153 $stat = Static_worker::query()->where('year_month', '=', $get_date)
154 ->where('user_id', '=', $worker->id) 154 ->where('user_id', '=', $worker->id)
155 ->get(); 155 ->get();
156 156
157 return view('worker', compact('Query', 'status_work')); 157 return view('worker', compact('Query', 'status_work'));
158 } 158 }
159 159
160 // скачать анкету соискателя 160 // скачать анкету соискателя
161 public function resume_download(Worker $worker) 161 public function resume_download(Worker $worker)
162 { 162 {
163 $status_work = $this->status_work; 163 $status_work = $this->status_work;
164 $Query = Worker::query()->with('users')->with('job_titles') 164 $Query = Worker::query()->with('users')->with('job_titles')
165 ->with('place_worker')->with('sertificate')->with('prev_company') 165 ->with('place_worker')->with('sertificate')->with('prev_company')
166 ->with('infobloks'); 166 ->with('infobloks');
167 $Query = $Query->where('id', '=', $worker->id); 167 $Query = $Query->where('id', '=', $worker->id);
168 $Query = $Query->get()->toArray(); 168 $Query = $Query->get()->toArray();
169 169
170 view()->share('Query',$Query); 170 view()->share('Query',$Query);
171 171
172 $pdf = PDF::loadView('layout.pdf', $Query); //->setPaper('a4', 'landscape'); 172 $pdf = PDF::loadView('layout.pdf', $Query); //->setPaper('a4', 'landscape');
173 173
174 return $pdf->stream(); 174 return $pdf->stream();
175 } 175 }
176 176
177 // Кабинет работника 177 // Кабинет работника
178 public function cabinet(Request $request) 178 public function cabinet(Request $request)
179 { 179 {
180 $get_date = date('Y.m'); 180 $get_date = date('Y.m');
181 181
182 $id = Auth()->user()->id; 182 $id = Auth()->user()->id;
183 $Worker = Worker::query()->with('users')->with('sertificate')->with('prev_company')-> 183 $Worker = Worker::query()->with('users')->with('sertificate')->with('prev_company')->
184 with('infobloks')->with('place_worker')-> 184 with('infobloks')->with('place_worker')->
185 WhereHas('users', 185 WhereHas('users',
186 function (Builder $query) use ($id) {$query->Where('id', $id); 186 function (Builder $query) use ($id) {$query->Where('id', $id);
187 })->get(); 187 })->get();
188 188
189 $Job_titles = Job_title::query()->OrderBy('name')->get(); 189 $Job_titles = Job_title::query()->OrderBy('name')->get();
190 $Infoblocks = infobloks::query()->OrderBy('name')->get(); 190 $Infoblocks = infobloks::query()->OrderBy('name')->get();
191 191
192 $stat = Static_worker::query()->where('year_month', '=', $get_date) 192 $stat = Static_worker::query()->where('year_month', '=', $get_date)
193 ->where('user_id', '=', $Worker[0]->id) 193 ->where('user_id', '=', $Worker[0]->id)
194 ->get(); 194 ->get();
195 195
196 $persent = 10; 196 $persent = 10;
197 if ((!empty($Worker[0]->status_work)) && (!empty($Worker[0]->telephone)) && 197 if ((!empty($Worker[0]->status_work)) && (!empty($Worker[0]->telephone)) &&
198 (!empty($Worker[0]->email)) && (!empty($Worker[0]->experience)) && 198 (!empty($Worker[0]->email)) && (!empty($Worker[0]->experience)) &&
199 (!empty($Worker[0]->city)) && (!empty($Worker[0]->old_year))) { 199 (!empty($Worker[0]->city)) && (!empty($Worker[0]->old_year))) {
200 $persent = $persent + 40; 200 $persent = $persent + 40;
201 } 201 }
202 202
203 if ($Worker[0]->sertificate->count() > 0) { 203 if ($Worker[0]->sertificate->count() > 0) {
204 $persent = $persent + 15; 204 $persent = $persent + 15;
205 } 205 }
206 206
207 if ($Worker[0]->infobloks->count() > 0) { 207 if ($Worker[0]->infobloks->count() > 0) {
208 $persent = $persent + 20; 208 $persent = $persent + 20;
209 } 209 }
210 210
211 if ($Worker[0]->prev_company->count() > 0) { 211 if ($Worker[0]->prev_company->count() > 0) {
212 $persent = $persent + 10; 212 $persent = $persent + 10;
213 } 213 }
214 214
215 if (!empty($Worker[0]->photo)) { 215 if (!empty($Worker[0]->photo)) {
216 // 5% 216 // 5%
217 $persent = $persent + 5; 217 $persent = $persent + 5;
218 } 218 }
219 219
220 if ($request->has('print')) { 220 if ($request->has('print')) {
221 dd($Worker); 221 dd($Worker);
222 } else { 222 } else {
223 return view('workers.cabinet', compact('Worker', 'persent', 'Job_titles', 'Infoblocks', 'stat')); 223 return view('workers.cabinet', compact('Worker', 'persent', 'Job_titles', 'Infoblocks', 'stat'));
224 } 224 }
225 } 225 }
226 226
227 // Сохранение данных 227 // Сохранение данных
228 public function cabinet_save(Worker $worker, Request $request) 228 public function cabinet_save(Worker $worker, Request $request)
229 { 229 {
230 $id = $worker->id; 230 $id = $worker->id;
231 $params = $request->all(); 231 $params = $request->all();
232 232
233 $job_title_id = $request->get('job_title_id'); 233 $job_title_id = $request->get('job_title_id');
234 234
235 unset($params['new_diplom']); 235 unset($params['new_diplom']);
236 unset($params['new_data_begin']); 236 unset($params['new_data_begin']);
237 unset($params['new_data_end']); 237 unset($params['new_data_end']);
238 unset($params['new_job_title']); 238 unset($params['new_job_title']);
239 unset($params['new_teplohod']); 239 unset($params['new_teplohod']);
240 unset($params['new_GWT']); 240 unset($params['new_GWT']);
241 unset($params['new_KBT']); 241 unset($params['new_KBT']);
242 unset($params['new_Begin_work']); 242 unset($params['new_Begin_work']);
243 unset($params['new_End_work']); 243 unset($params['new_End_work']);
244 unset($params['new_name_company']); 244 unset($params['new_name_company']);
245 245
246 $rules = [ 246 $rules = [
247 'surname' => ['required', 'string', 'max:255'], 247 'surname' => ['required', 'string', 'max:255'],
248 'name_man' => ['required', 'string', 'max:255'], 248 'name_man' => ['required', 'string', 'max:255'],
249 'email' => ['required', 'string', 'email', 'max:255'], 249 'email' => ['required', 'string', 'email', 'max:255'],
250 250
251 ]; 251 ];
252 252
253 $messages = [ 253 $messages = [
254 'required' => 'Укажите обязательное поле', 254 'required' => 'Укажите обязательное поле',
255 'min' => [ 255 'min' => [
256 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 256 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
257 'integer' => 'Поле «:attribute» должно быть :min или больше', 257 'integer' => 'Поле «:attribute» должно быть :min или больше',
258 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 258 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
259 ], 259 ],
260 'max' => [ 260 'max' => [
261 'string' => 'Поле «:attribute» должно быть не больше :max символов', 261 'string' => 'Поле «:attribute» должно быть не больше :max символов',
262 'integer' => 'Поле «:attribute» должно быть :max или меньше', 262 'integer' => 'Поле «:attribute» должно быть :max или меньше',
263 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 263 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
264 ] 264 ]
265 ]; 265 ];
266 266
267 $validator = Validator::make($params, $rules, $messages); 267 $validator = Validator::make($params, $rules, $messages);
268 268
269 if ($validator->fails()) { 269 if ($validator->fails()) {
270 return redirect()->route('worker.cabinet')->withErrors($validator); 270 return redirect()->route('worker.cabinet')->withErrors($validator);
271 } else { 271 } else {
272 272
273 if ($request->has('photo')) { 273 if ($request->has('photo')) {
274 if (!empty($Worker->photo)) { 274 if (!empty($Worker->photo)) {
275 Storage::delete($Worker->photo); 275 Storage::delete($Worker->photo);
276 } 276 }
277 $params['photo'] = $request->file('photo')->store("worker/$id", 'public'); 277 $params['photo'] = $request->file('photo')->store("worker/$id", 'public');
278 } 278 }
279 279
280 if ($request->has('file')) { 280 if ($request->has('file')) {
281 if (!empty($Worker->file)) { 281 if (!empty($Worker->file)) {
282 Storage::delete($Worker->file); 282 Storage::delete($Worker->file);
283 } 283 }
284 $params['file'] = $request->file('file')->store("worker/$id", 'public'); 284 $params['file'] = $request->file('file')->store("worker/$id", 'public');
285 } 285 }
286 286
287 $id_wor = $worker->update($params); 287 $id_wor = $worker->update($params);
288 288
289 $use = User_Model::find($id_wor); 289 $use = User_Model::find($id_wor);
290 $use->surname = $request->get('surname'); 290 $use->surname = $request->get('surname');
291 $use->name_man = $request->get('name_man'); 291 $use->name_man = $request->get('name_man');
292 $use->surname2 = $request->get('surname2'); 292 $use->surname2 = $request->get('surname2');
293 293
294 $use->save(); 294 $use->save();
295 $worker->job_titles()->sync($job_title_id); 295 $worker->job_titles()->sync($job_title_id);
296 296
297 return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены'); 297 return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены');
298 } 298 }
299 } 299 }
300 300
301 // Сообщения данные 301 // Сообщения данные
302 public function messages($type_message) 302 public function messages($type_message)
303 { 303 {
304 $user_id = Auth()->user()->id; 304 $user_id = Auth()->user()->id;
305 305
306 $messages_input = Message::query()->with('vacancies')->with('user_from')-> 306 $messages_input = Message::query()->with('vacancies')->with('user_from')->
307 Where('to_user_id', $user_id)->OrderByDesc('created_at'); 307 Where('to_user_id', $user_id)->OrderByDesc('created_at');
308 308
309 $messages_output = Message::query()->with('vacancies')-> 309 $messages_output = Message::query()->with('vacancies')->
310 with('user_to')->where('user_id', $user_id)-> 310 with('user_to')->where('user_id', $user_id)->
311 OrderByDesc('created_at'); 311 OrderByDesc('created_at');
312 312
313 313
314 $count_input = $messages_input->count(); 314 $count_input = $messages_input->count();
315 $count_output = $messages_output->count(); 315 $count_output = $messages_output->count();
316 316
317 if ($type_message == 'input') { 317 if ($type_message == 'input') {
318 $messages = $messages_input->paginate(15); 318 $messages = $messages_input->paginate(15);
319 } 319 }
320 320
321 if ($type_message == 'output') { 321 if ($type_message == 'output') {
322 $messages = $messages_output->paginate(15); 322 $messages = $messages_output->paginate(15);
323 } 323 }
324 // Вернуть все 100% 324 // Вернуть все 100%
325 return view('workers.messages', compact('messages', 'count_input', 'count_output', 'type_message', 'user_id')); 325 return view('workers.messages', compact('messages', 'count_input', 'count_output', 'type_message', 'user_id'));
326 } 326 }
327 327
328 // Избранный 328 // Избранный
329 public function favorite() 329 public function favorite()
330 { 330 {
331 return view('workers.favorite'); 331 return view('workers.favorite');
332 } 332 }
333 333
334 // Сменить пароль 334 // Сменить пароль
335 public function new_password() 335 public function new_password()
336 { 336 {
337 $email = Auth()->user()->email; 337 $email = Auth()->user()->email;
338 return view('workers.new_password', compact('email')); 338 return view('workers.new_password', compact('email'));
339 } 339 }
340 340
341 // Обновление пароля 341 // Обновление пароля
342 public function save_new_password(Request $request) { 342 public function save_new_password(Request $request) {
343 $use = Auth()->user(); 343 $use = Auth()->user();
344 $request->validate([ 344 $request->validate([
345 'password' => 'required|string', 345 'password' => 'required|string',
346 'new_password' => 'required|string', 346 'new_password' => 'required|string',
347 'new_password2' => 'required|string' 347 'new_password2' => 'required|string'
348 ]); 348 ]);
349 349
350 if ($request->get('new_password') == $request->get('new_password2')) 350 if ($request->get('new_password') == $request->get('new_password2'))
351 if ($request->get('password') !== $request->get('new_password')) { 351 if ($request->get('password') !== $request->get('new_password')) {
352 $credentials = $request->only('email', 'password'); 352 $credentials = $request->only('email', 'password');
353 if (Auth::attempt($credentials, $request->has('save_me'))) { 353 if (Auth::attempt($credentials, $request->has('save_me'))) {
354 354
355 if (!is_null($use->email_verified_at)){ 355 if (!is_null($use->email_verified_at)){
356 356
357 $user_data = User_Model::find($use->id); 357 $user_data = User_Model::find($use->id);
358 $user_data->update([ 358 $user_data->update([
359 'password' => Hash::make($request->get('new_password')), 359 'password' => Hash::make($request->get('new_password')),
360 'pubpassword' => base64_encode($request->get('new_password')), 360 'pubpassword' => base64_encode($request->get('new_password')),
361 ]); 361 ]);
362 return redirect() 362 return redirect()
363 ->route('worker.new_password') 363 ->route('worker.new_password')
364 ->with('success', 'Поздравляю! Вы обновили свой пароль!'); 364 ->with('success', 'Поздравляю! Вы обновили свой пароль!');
365 } 365 }
366 366
367 return redirect() 367 return redirect()
368 ->route('worker.new_password') 368 ->route('worker.new_password')
369 ->withError('Данная учетная запись не было верифицированна!'); 369 ->withError('Данная учетная запись не было верифицированна!');
370 } 370 }
371 } 371 }
372 372
373 return redirect() 373 return redirect()
374 ->route('worker.new_password') 374 ->route('worker.new_password')
375 ->withErrors('Не совпадение данных, обновите пароли!'); 375 ->withErrors('Не совпадение данных, обновите пароли!');
376 } 376 }
377 377
378 // Удаление профиля форма 378 // Удаление профиля форма
379 public function delete_profile() 379 public function delete_profile()
380 { 380 {
381 $login = Auth()->user()->email; 381 $login = Auth()->user()->email;
382 return view('workers.delete_profile', compact('login')); 382 return view('workers.delete_profile', compact('login'));
383 } 383 }
384 384
385 // Удаление профиля код 385 // Удаление профиля код
386 public function delete_profile_result(Request $request) { 386 public function delete_profile_result(Request $request) {
387 $Answer = $request->all(); 387 $Answer = $request->all();
388 $user_id = Auth()->user()->id; 388 $user_id = Auth()->user()->id;
389 $request->validate([ 389 $request->validate([
390 'password' => 'required|string', 390 'password' => 'required|string',
391 ]); 391 ]);
392 392
393 $credentials = $request->only('email', 'password'); 393 $credentials = $request->only('email', 'password');
394 if (Auth::attempt($credentials)) { 394 if (Auth::attempt($credentials)) {
395 Auth::logout(); 395 Auth::logout();
396 $it = User_Model::find($user_id); 396 $it = User_Model::find($user_id);
397 $it->delete(); 397 $it->delete();
398 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); 398 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
399 } else { 399 } else {
400 return redirect()->route('worker.delete_profile') 400 return redirect()->route('worker.delete_profile')
401 ->withErrors( 'Неверный пароль! Нужен корректный пароль'); 401 ->withErrors( 'Неверный пароль! Нужен корректный пароль');
402 } 402 }
403 } 403 }
404 404
405 // Регистрация соискателя 405 // Регистрация соискателя
406 public function register_worker(Request $request) 406 public function register_worker(Request $request)
407 { 407 {
408 $params = $request->all(); 408 $params = $request->all();
409 409
410 410
411 dd($params); 411 dd($params);
412 412
413 $rules = [ 413 $rules = [
414 'surname' => ['required', 'string', 'max:255'], 414 'surname' => ['required', 'string', 'max:255'],
415 'name_man' => ['required', 'string', 'max:255'], 415 'name_man' => ['required', 'string', 'max:255'],
416 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 416 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
417 'password' => ['required', 'string', 'min:8'] 417 'password' => ['required', 'string', 'min:8']
418 ]; 418 ];
419 419
420 $messages = [ 420 $messages = [
421 'required' => 'Укажите обязательное поле', 421 'required' => 'Укажите обязательное поле',
422 'min' => [ 422 'min' => [
423 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 423 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
424 'integer' => 'Поле «:attribute» должно быть :min или больше', 424 'integer' => 'Поле «:attribute» должно быть :min или больше',
425 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 425 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
426 ], 426 ],
427 'max' => [ 427 'max' => [
428 'string' => 'Поле «:attribute» должно быть не больше :max символов', 428 'string' => 'Поле «:attribute» должно быть не больше :max символов',
429 'integer' => 'Поле «:attribute» должно быть :max или меньше', 429 'integer' => 'Поле «:attribute» должно быть :max или меньше',
430 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 430 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
431 ] 431 ]
432 ]; 432 ];
433 433
434 if ($request->get('password') !== $request->get('confirmed')){ 434 if ($request->get('password') !== $request->get('confirmed')){
435 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); 435 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля"));
436 } 436 }
437 437
438 if (($request->has('politik')) && ($request->get('politik') == 1)) { 438 if (($request->has('politik')) && ($request->get('politik') == 1)) {
439 $validator = Validator::make($request->all(), $rules, $messages); 439 $validator = Validator::make($request->all(), $rules, $messages);
440 440
441 if ($validator->fails()) { 441 if ($validator->fails()) {
442 return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); 442 return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе."));
443 } else { 443 } else {
444 $user = $this->create($params); 444 $user = $this->create($params);
445 event(new Registered($user)); 445 event(new Registered($user));
446 446
447 Auth::guard()->login($user); 447 Auth::guard()->login($user);
448 } 448 }
449 449
450 if ($user) { 450 if ($user) {
451 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));; 451 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));;
452 } else { 452 } else {
453 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!")); 453 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!"));
454 } 454 }
455 455
456 } else { 456 } else {
457 return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!")); 457 return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!"));
458 } 458 }
459 459
460 460
461 } 461 }
462 462
463 463
464 // Звездная оценка и ответ 464 // Звездная оценка и ответ
465 public function stars_answer(Request $request) { 465 public function stars_answer(Request $request) {
466 $params = $request->all(); 466 $params = $request->all();
467 $rules = [ 467 $rules = [
468 'message' => ['required', 'string', 'max:255'], 468 'message' => ['required', 'string', 'max:255'],
469 ]; 469 ];
470 470
471 $messages = [ 471 $messages = [
472 'required' => 'Укажите обязательное поле', 472 'required' => 'Укажите обязательное поле',
473 'min' => [ 473 'min' => [
474 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 474 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
475 'integer' => 'Поле «:attribute» должно быть :min или больше', 475 'integer' => 'Поле «:attribute» должно быть :min или больше',
476 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 476 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
477 ], 477 ],
478 'max' => [ 478 'max' => [
479 'string' => 'Поле «:attribute» должно быть не больше :max символов', 479 'string' => 'Поле «:attribute» должно быть не больше :max символов',
480 'integer' => 'Поле «:attribute» должно быть :max или меньше', 480 'integer' => 'Поле «:attribute» должно быть :max или меньше',
481 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 481 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
482 ] 482 ]
483 ]; 483 ];
484 $response_worker = ResponseWork::create($params); 484 $response_worker = ResponseWork::create($params);
485 return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!'); 485 return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!');
486 } 486 }
487 487
488 // Создание пользователя 488 // Создание пользователя
489 protected function create(array $data) 489 protected function create(array $data)
490 { 490 {
491 $Use = new User(); 491 $Use = new User();
492 $Code_user = $Use->create([ 492 $Code_user = $Use->create([
493 'name' => $data['surname']." ".$data['name_man'], 493 'name' => $data['surname']." ".$data['name_man'],
494 'name_man' => $data['name_man'], 494 'name_man' => $data['name_man'],
495 'surname' => $data['surname'], 495 'surname' => $data['surname'],
496 'surname2' => $data['surname2'], 496 'surname2' => $data['surname2'],
497 'subscribe_email' => $data['email'], 497 'subscribe_email' => $data['email'],
498 'email' => $data['email'], 498 'email' => $data['email'],
499 'telephone' => $data['telephone'], 499 'telephone' => $data['telephone'],
500 'password' => Hash::make($data['password']), 500 'password' => Hash::make($data['password']),
501 'pubpassword' => base64_encode($data['password']), 501 'pubpassword' => base64_encode($data['password']),
502 'email_verified_at' => Carbon::now() 502 'email_verified_at' => Carbon::now()
503 ]); 503 ]);
504 if ($Code_user->id > 0) { 504 if ($Code_user->id > 0) {
505 $Worker = new Worker(); 505 $Worker = new Worker();
506 $Worker->user_id = $Code_user->id; 506 $Worker->user_id = $Code_user->id;
507 $Worker->position_work = $data['job_titles']; 507 $Worker->position_work = $data['job_titles'];
508 $Worker->email = $data['email']; 508 $Worker->email = $data['email'];
509 $Worker->telephone = $data['telephone']; 509 $Worker->telephone = $data['telephone'];
510 $Worker->save(); 510 $Worker->save();
511 511
512 return $Code_user; 512 return $Code_user;
513 } 513 }
514 } 514 }
515 515
516 // Вакансии избранные 516 // Вакансии избранные
517 public function colorado(Request $request) { 517 public function colorado(Request $request) {
518 $IP_address = RusDate::ip_addr_client(); 518 $IP_address = RusDate::ip_addr_client();
519 $Arr = Like_vacancy::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get(); 519 $Arr = Like_vacancy::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get();
520 520
521 if ($Arr->count()) { 521 if ($Arr->count()) {
522 $A = Array(); 522 $A = Array();
523 foreach ($Arr as $it) { 523 foreach ($Arr as $it) {
524 $A[] = $it->code_record; 524 $A[] = $it->code_record;
525 } 525 }
526 526
527 $Query = Ad_employer::query()->whereIn('id', $A); 527 $Query = Ad_employer::query()->whereIn('id', $A);
528 } else { 528 } else {
529 $Query = Ad_employer::query(); 529 $Query = Ad_employer::query()->where('id', '=', '0');
530 } 530 }
531 531
532 $Query = $Query->with('jobs')-> 532 $Query = $Query->with('jobs')->
533 with('cat')-> 533 with('cat')->
534 with('employer')-> 534 with('employer')->
535 whereHas('jobs_code', function ($query) use ($request) { 535 whereHas('jobs_code', function ($query) use ($request) {
536 if ($request->ajax()) { 536 if ($request->ajax()) {
537 if (null !== ($request->get('job'))) { 537 if (null !== ($request->get('job'))) {
538 $query->where('job_title_id', $request->get('job')); 538 $query->where('job_title_id', $request->get('job'));
539 } 539 }
540 } 540 }
541 })->select('ad_employers.*'); 541 })->select('ad_employers.*');
542 542
543 $Job_title = Job_title::query()->OrderBy('name')->get(); 543 $Job_title = Job_title::query()->OrderBy('name')->get();
544 544
545 $Query_count = $Query->count(); 545 $Query_count = $Query->count();
546 546
547 $Query = $Query->OrderBy('updated_at')->paginate(3); 547 $Query = $Query->OrderBy('updated_at')->paginate(3);
548 548
549 return view('workers.favorite', compact('Query', 549 return view('workers.favorite', compact('Query',
550 'Query_count', 550 'Query_count',
551 'Job_title')); 551 'Job_title'));
552 552
553 } 553 }
554 554
555 //Переписка 555 //Переписка
556 public function dialog(User_Model $user1, User_Model $user2) { 556 public function dialog(User_Model $user1, User_Model $user2) {
557 if (isset($user2->id)) { 557 if (isset($user2->id)) {
558 $companion = User_Model::query()->with('workers')-> 558 $companion = User_Model::query()->with('workers')->
559 with('employers')-> 559 with('employers')->
560 where('id', $user2->id)->first(); 560 where('id', $user2->id)->first();
561 } 561 }
562 562
563 $Messages = Message::query()->with('response')->where(function($query) use ($user1, $user2) { 563 $Messages = Message::query()->with('response')->where(function($query) use ($user1, $user2) {
564 $query->where('user_id', $user1->id)->where('to_user_id', $user2->id); 564 $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
565 })->orWhere(function($query) use ($user1, $user2) { 565 })->orWhere(function($query) use ($user1, $user2) {
566 $query->where('user_id', $user2->id)->where('to_user_id', $user1->id); 566 $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
567 })->OrderBy('created_at')->get(); 567 })->OrderBy('created_at')->get();
568 568
569 $id_vac = null; 569 $id_vac = null;
570 foreach ($Messages as $it) { 570 foreach ($Messages as $it) {
571 if (isset($it->response)) { 571 if (isset($it->response)) {
572 foreach ($it->response as $r) { 572 foreach ($it->response as $r) {
573 if (isset($r->ad_employer_id)) { 573 if (isset($r->ad_employer_id)) {
574 $id_vac = $r->ad_employer_id; 574 $id_vac = $r->ad_employer_id;
575 break; 575 break;
576 } 576 }
577 } 577 }
578 } 578 }
579 if (!is_null($id_vac)) break; 579 if (!is_null($id_vac)) break;
580 } 580 }
581 581
582 $ad_employer = null; 582 $ad_employer = null;
583 if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first(); 583 if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first();
584 $sender = $user1; 584 $sender = $user1;
585 585
586 return view('workers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer')); 586 return view('workers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer'));
587 } 587 }
588 588
589 // Даунылоады 589 // Даунылоады
590 public function download(Worker $worker) { 590 public function download(Worker $worker) {
591 $arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...']; 591 $arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...'];
592 view()->share('house',$arr_house); 592 view()->share('house',$arr_house);
593 $pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape'); 593 $pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape');
594 return $pdf->stream(); 594 return $pdf->stream();
595 } 595 }
596 596
597 // Поднятие анкеты 597 // Поднятие анкеты
598 public function up(Worker $worker) { 598 public function up(Worker $worker) {
599 $worker->updated_at = Carbon::now(); 599 $worker->updated_at = Carbon::now();
600 $worker->save(); 600 $worker->save();
601 return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных'); 601 return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных');
602 } 602 }
603 603
604 // Добавление сертификата 604 // Добавление сертификата
605 public function add_serificate(Request $request) { 605 public function add_serificate(Request $request) {
606 $params = $request->all(); 606 $params = $request->all();
607 $params['date_begin'] = date('d.m.Y', strtotime($params['date_begin'])); 607 $params['date_begin'] = date('d.m.Y', strtotime($params['date_begin']));
608 $params['end_begin'] = date('d.m.Y', strtotime($params['end_begin'])); 608 $params['end_begin'] = date('d.m.Y', strtotime($params['end_begin']));
609 $Sertificate = new sertification(); 609 $Sertificate = new sertification();
610 $Sertificate->create($params); 610 $Sertificate->create($params);
611 $Docs = sertification::query()->where('worker_id', $request->get('worker_id'))->get(); 611 $Docs = sertification::query()->where('worker_id', $request->get('worker_id'))->get();
612 return view('ajax.documents', compact('Docs')); 612 return view('ajax.documents', compact('Docs'));
613 } 613 }
614 614
615 615
616 // Удалить сертификат 616 // Удалить сертификат
617 public function delete_sertificate(sertification $doc) { 617 public function delete_sertificate(sertification $doc) {
618 $doc->delete(); 618 $doc->delete();
619 619
620 return redirect()->route('worker.cabinet'); 620 return redirect()->route('worker.cabinet');
621 } 621 }
622 622
623 // Добавление диплома 623 // Добавление диплома
624 public function add_diplom_ajax(Request $request) { 624 public function add_diplom_ajax(Request $request) {
625 // конец 625 // конец
626 $params = $request->all(); 626 $params = $request->all();
627 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); 627 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count();
628 628
629 if ($count == 0) $dop_info = Dop_info::create($params); 629 if ($count == 0) $dop_info = Dop_info::create($params);
630 $Infoblocks = infobloks::query()->get(); 630 $Infoblocks = infobloks::query()->get();
631 $Worker = Worker::query()->where('id', $request->get('worker_id'))->get(); 631 $Worker = Worker::query()->where('id', $request->get('worker_id'))->get();
632 $data = Dop_info::query()->where('worker_id', $request->has('worker_id')); 632 $data = Dop_info::query()->where('worker_id', $request->has('worker_id'));
633 return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker')); 633 return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker'));
634 } 634 }
635 635
636 // Добавление диплома без ajax 636 // Добавление диплома без ajax
637 public function add_diplom(Worker $worker) { 637 public function add_diplom(Worker $worker) {
638 $worker_id = $worker->id; 638 $worker_id = $worker->id;
639 $Infoblocks = infobloks::query()->get(); 639 $Infoblocks = infobloks::query()->get();
640 return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks')); 640 return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks'));
641 } 641 }
642 // Сохранить 642 // Сохранить
643 // Сохраняю диплом 643 // Сохраняю диплом
644 public function add_diplom_save(Request $request) { 644 public function add_diplom_save(Request $request) {
645 $params = $request->all(); 645 $params = $request->all();
646 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); 646 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count();
647 if ($count == 0) $dop_info = Dop_info::create($params); 647 if ($count == 0) $dop_info = Dop_info::create($params);
648 return redirect()->route('worker.cabinet'); 648 return redirect()->route('worker.cabinet');
649 } 649 }
650 650
651 // Добавление стандартного документа 651 // Добавление стандартного документа
652 public function add_document(Worker $worker) { 652 public function add_document(Worker $worker) {
653 return view('workers.docs', compact('worker')); 653 return view('workers.docs', compact('worker'));
654 } 654 }
655 655
656 //Сохранение стандартого документа 656 //Сохранение стандартого документа
657 public function add_document_save(DocumentsRequest $request) { 657 public function add_document_save(DocumentsRequest $request) {
658 $params = $request->all(); 658 $params = $request->all();
659 $place_work = place_works::create($params); 659 $place_work = place_works::create($params);
660 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно добавили запись!'); 660 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно добавили запись!');
661 } 661 }
662 662
663 // Редактирование документа 663 // Редактирование документа
664 public function edit_document(place_works $doc, Worker $worker) { 664 public function edit_document(place_works $doc, Worker $worker) {
665 return view('workers.docs-edit', compact('doc', 'worker')); 665 return view('workers.docs-edit', compact('doc', 'worker'));
666 } 666 }
667 667
668 //Сохранение отредактированного документа 668 //Сохранение отредактированного документа
669 public function edit_document_save(DocumentsRequest $request, place_works $doc) { 669 public function edit_document_save(DocumentsRequest $request, place_works $doc) {
670 $params = $request->all(); 670 $params = $request->all();
671 $doc->update($params); 671 $doc->update($params);
672 672
673 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); 673 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!');
674 } 674 }
675 675
676 // Удаление документа 676 // Удаление документа
677 public function delete_document(place_works $doc) { 677 public function delete_document(place_works $doc) {
678 $doc->delete(); 678 $doc->delete();
679 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); 679 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!');
680 } 680 }
681 681
682 //Отправка нового сообщения 682 //Отправка нового сообщения
683 public function new_message(Request $request) { 683 public function new_message(Request $request) {
684 $params = $request->all(); 684 $params = $request->all();
685 685
686 $id = $params['send_user_id']; 686 $id = $params['send_user_id'];
687 $message = new Message(); 687 $message = new Message();
688 $message->user_id = $params['send_user_id']; 688 $message->user_id = $params['send_user_id'];
689 $message->to_user_id = $params['send_to_user_id']; 689 $message->to_user_id = $params['send_to_user_id'];
690 $message->title = $params['send_title']; 690 $message->title = $params['send_title'];
691 $message->text = $params['send_text']; 691 $message->text = $params['send_text'];
692 if ($request->has('send_file')) { 692 if ($request->has('send_file')) {
693 $message->file = $request->file('send_file')->store("worker/$id", 'public'); 693 $message->file = $request->file('send_file')->store("worker/$id", 'public');
694 } 694 }
695 $message->flag_new = 1; 695 $message->flag_new = 1;
696 $id_message = $message->save(); 696 $id_message = $message->save();
697 697
698 $data['message_id'] = $id_message; 698 $data['message_id'] = $id_message;
699 $data['ad_employer_id'] = $params['send_vacancy']; 699 $data['ad_employer_id'] = $params['send_vacancy'];
700 $data['job_title_id'] = $params['send_job_title_id']; 700 $data['job_title_id'] = $params['send_job_title_id'];
701 $data['flag'] = 1; 701 $data['flag'] = 1;
702 $ad_responce = ad_response::create($data); 702 $ad_responce = ad_response::create($data);
703 return redirect()->route('worker.messages', ['type_message' => 'output']); 703 return redirect()->route('worker.messages', ['type_message' => 'output']);
704 } 704 }
705 705
706 } 706 }
707 707
708 708