Commit 46df2bfd5900de73f63118f1be52e24a8ca59534

Authored by Андрей Ларионов
Exists in master

Merge branch 'master' of http://gitlab.nologostudio.ru/alarionov/rekamore-su

Showing 1 changed file 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\BaseUser_min_Request; 7 use App\Http\Requests\BaseUser_min_Request;
8 use App\Http\Requests\FlotRequest; 8 use App\Http\Requests\FlotRequest;
9 use App\Http\Requests\MessagesRequiest; 9 use App\Http\Requests\MessagesRequiest;
10 use App\Http\Requests\VacancyRequestEdit; 10 use App\Http\Requests\VacancyRequestEdit;
11 use App\Mail\MailCreateEmployer; 11 use App\Mail\MailCreateEmployer;
12 use App\Mail\MailSotrudnichestvo; 12 use App\Mail\MailSotrudnichestvo;
13 use App\Mail\SendAllMessages; 13 use App\Mail\SendAllMessages;
14 use App\Models\Ad_employer; 14 use App\Models\Ad_employer;
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\Chat; 17 use App\Models\Chat;
18 use App\Models\Employer; 18 use App\Models\Employer;
19 use App\Models\Flot; 19 use App\Models\Flot;
20 use App\Models\Job_title; 20 use App\Models\Job_title;
21 use App\Models\Like_worker; 21 use App\Models\Like_worker;
22 use App\Models\Message; 22 use App\Models\Message;
23 use App\Models\Worker; 23 use App\Models\Worker;
24 use Carbon\Carbon; 24 use Carbon\Carbon;
25 use Illuminate\Auth\Events\Registered; 25 use Illuminate\Auth\Events\Registered;
26 use Illuminate\Database\Eloquent\Builder; 26 use Illuminate\Database\Eloquent\Builder;
27 use Illuminate\Http\Request; 27 use Illuminate\Http\Request;
28 use Illuminate\Support\Facades\Auth; 28 use Illuminate\Support\Facades\Auth;
29 use Illuminate\Support\Facades\Hash; 29 use Illuminate\Support\Facades\Hash;
30 use Illuminate\Support\Facades\Mail; 30 use Illuminate\Support\Facades\Mail;
31 use Illuminate\Support\Facades\Storage; 31 use Illuminate\Support\Facades\Storage;
32 use App\Models\User as User_Model; 32 use App\Models\User as User_Model;
33 use Illuminate\Support\Facades\Validator; 33 use Illuminate\Support\Facades\Validator;
34 use App\Enums\DbExportColumns; 34 use App\Enums\DbExportColumns;
35 35
36 class EmployerController extends Controller 36 class EmployerController extends Controller
37 { 37 {
38 public function vacancie($vacancy, Request $request) { 38 public function vacancie($vacancy, Request $request) {
39 $title = 'Заголовок вакансии'; 39 $title = 'Заголовок вакансии';
40 $Query = Ad_employer::with('jobs')-> 40 $Query = Ad_employer::with('jobs')->
41 with('cat')-> 41 with('cat')->
42 with('employer')-> 42 with('employer')->
43 with('jobs_code')-> 43 with('jobs_code')->
44 select('ad_employers.*')-> 44 select('ad_employers.*')->
45 where('id', '=', $vacancy)->get(); 45 where('id', '=', $vacancy)->get();
46 46
47 if (isset(Auth()->user()->id)) 47 if (isset(Auth()->user()->id))
48 $uid = Auth()->user()->id; 48 $uid = Auth()->user()->id;
49 else 49 else
50 $uid = 0; 50 $uid = 0;
51 $title = $Query[0]->name; 51 $title = $Query[0]->name;
52 if ($request->ajax()) { 52 if ($request->ajax()) {
53 return view('ajax.vacance-item', compact('Query','uid')); 53 return view('ajax.vacance-item', compact('Query','uid'));
54 } else { 54 } else {
55 return view('vacance-item', compact('title', 'Query', 'uid')); 55 return view('vacance-item', compact('title', 'Query', 'uid'));
56 } 56 }
57 } 57 }
58 58
59 public function logout() { 59 public function logout() {
60 Auth::logout(); 60 Auth::logout();
61 return redirect()->route('index') 61 return redirect()->route('index')
62 ->with('success', 'Вы вышли из личного кабинета'); 62 ->with('success', 'Вы вышли из личного кабинета');
63 } 63 }
64 64
65 public function employer_info() { 65 public function employer_info() {
66 // код юзера 66 // код юзера
67 $user_info = Auth()->user(); 67 $user_info = Auth()->user();
68 // вьюшка для вывода данных 68 // вьюшка для вывода данных
69 return view('employers.info', compact('user_info')); 69 return view('employers.info', compact('user_info'));
70 } 70 }
71 71
72 public function employer_info_save(User_Model $user, BaseUser_min_Request $request) { 72 public function employer_info_save(User_Model $user, BaseUser_min_Request $request) {
73 // Все данные через реквест 73 // Все данные через реквест
74 $all = $request->all(); 74 $all = $request->all();
75 unset($all['_token']); 75 unset($all['_token']);
76 // обновление 76 // обновление
77 $user->update($all); 77 $user->update($all);
78 return redirect()->route('employer.employer_info'); 78 return redirect()->route('employer.employer_info');
79 } 79 }
80 80
81 public function cabinet() { 81 public function cabinet() {
82 $id = Auth()->user()->id; 82 $id = Auth()->user()->id;
83 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 83 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
84 WhereHas('users', 84 WhereHas('users',
85 function (Builder $query) use ($id) {$query->Where('id', $id); 85 function (Builder $query) use ($id) {$query->Where('id', $id);
86 })->get(); 86 })->get();
87 return view('employers.cabinet45', compact('Employer')); 87 return view('employers.cabinet45', compact('Employer'));
88 } 88 }
89 89
90 public function slider_flot() { 90 public function slider_flot() {
91 $id = Auth()->user()->id; 91 $id = Auth()->user()->id;
92 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 92 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
93 WhereHas('users', 93 WhereHas('users',
94 function (Builder $query) use ($id) {$query->Where('id', $id); 94 function (Builder $query) use ($id) {$query->Where('id', $id);
95 })->get(); 95 })->get();
96 return view('employers.fly-flot', compact('Employer')); 96 return view('employers.fly-flot', compact('Employer'));
97 } 97 }
98 98
99 public function cabinet_save(Employer $Employer, Request $request) { 99 public function cabinet_save(Employer $Employer, Request $request) {
100 $params = $request->all(); 100 $params = $request->all();
101 $params['user_id'] = Auth()->user()->id; 101 $params['user_id'] = Auth()->user()->id;
102 $id = $Employer->id; 102 $id = $Employer->id;
103 103
104 if ($request->has('logo')) { 104 if ($request->has('logo')) {
105 if (!empty($Employer->logo)) { 105 if (!empty($Employer->logo)) {
106 Storage::delete($Employer->logo); 106 Storage::delete($Employer->logo);
107 } 107 }
108 $params['logo'] = $request->file('logo')->store("employer/$id", 'public'); 108 $params['logo'] = $request->file('logo')->store("employer/$id", 'public');
109 } 109 }
110 110
111 $Employer->update($params); 111 $Employer->update($params);
112 112
113 return redirect()->route('employer.cabinet')->with('success', 'Данные были успешно сохранены'); 113 return redirect()->route('employer.cabinet')->with('success', 'Данные были успешно сохранены');
114 } 114 }
115 115
116 public function save_add_flot(FlotRequest $request) { 116 public function save_add_flot(FlotRequest $request) {
117 // отмена 117 // отмена
118 $params = $request->all(); 118 $params = $request->all();
119 119
120 if ($request->has('image')) { 120 if ($request->has('image')) {
121 $params['image'] = $request->file('image')->store("flot", 'public'); 121 $params['image'] = $request->file('image')->store("flot", 'public');
122 } 122 }
123 Flot::create($params); 123 Flot::create($params);
124 $data_flots = Flot::query()->where('employer_id', $request->get('employer_if'))->get(); 124 $data_flots = Flot::query()->where('employer_id', $request->get('employer_if'))->get();
125 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен'); 125 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен');
126 } 126 }
127 127
128 public function edit_flot(Flot $Flot, Employer $Employer) { 128 public function edit_flot(Flot $Flot, Employer $Employer) {
129 return view('employers.edit-flot', compact('Flot', 'Employer')); 129 return view('employers.edit-flot', compact('Flot', 'Employer'));
130 } 130 }
131 131
132 public function update_flot(FlotRequest $request, Flot $Flot) { 132 public function update_flot(FlotRequest $request, Flot $Flot) {
133 $params = $request->all(); 133 $params = $request->all();
134 134
135 if ($request->has('image')) { 135 if ($request->has('image')) {
136 if (!empty($flot->image)) { 136 if (!empty($flot->image)) {
137 Storage::delete($flot->image); 137 Storage::delete($flot->image);
138 } 138 }
139 $params['image'] = $request->file('image')->store("flot", 'public'); 139 $params['image'] = $request->file('image')->store("flot", 'public');
140 } else { 140 } else {
141 if (!empty($flot->image)) $params['image'] = $flot->image; 141 if (!empty($flot->image)) $params['image'] = $flot->image;
142 } 142 }
143 143
144 $Flot->update($params); 144 $Flot->update($params);
145 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен'); 145 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен');
146 } 146 }
147 147
148 public function delete_flot(Flot $Flot) { 148 public function delete_flot(Flot $Flot) {
149 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get(); 149 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get();
150 150
151 if (isset($Flot->id)) $Flot->delete(); 151 if (isset($Flot->id)) $Flot->delete();
152 return redirect()->route('employer.slider_flot')->with('success', 'Корабль был удален'); 152 return redirect()->route('employer.slider_flot')->with('success', 'Корабль был удален');
153 } 153 }
154 154
155 // Форма добавления вакансий 155 // Форма добавления вакансий
156 public function cabinet_vacancie() { 156 public function cabinet_vacancie() {
157 $id = Auth()->user()->id; 157 $id = Auth()->user()->id;
158 158
159 if (Auth()->user()->is_public) { 159 if (Auth()->user()->is_public) {
160 $categories = Category::query()->active()->get(); 160 $categories = Category::query()->active()->get();
161 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 161 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
162 where('is_remove', '=', '0')-> 162 where('is_remove', '=', '0')->
163 where('is_bd', '=', '0')-> 163 where('is_bd', '=', '0')->
164 get(); 164 get();
165 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 165 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
166 WhereHas('users', 166 WhereHas('users',
167 function (Builder $query) use ($id) { 167 function (Builder $query) use ($id) {
168 $query->Where('id', $id); 168 $query->Where('id', $id);
169 })->get(); 169 })->get();
170 return view('employers.add_vacancy', compact('Employer', 'jobs', 'categories')); 170 return view('employers.add_vacancy', compact('Employer', 'jobs', 'categories'));
171 } else { 171 } else {
172 return redirect()->route('employer.cabinet_vacancie_danger'); 172 return redirect()->route('employer.cabinet_vacancie_danger');
173 } 173 }
174 } 174 }
175 175
176 // Форма предупреждения об оплате 176 // Форма предупреждения об оплате
177 public function cabinet_vacancie_danger() { 177 public function cabinet_vacancie_danger() {
178 return view('employers.add_vacancy_danger'); 178 return view('employers.add_vacancy_danger');
179 } 179 }
180 180
181 // Сохранение вакансии 181 // Сохранение вакансии
182 public function cabinet_vacancy_save1(VacancyRequestEdit $request) { 182 public function cabinet_vacancy_save1(VacancyRequestEdit $request) {
183 $params_emp = $request->all(); 183 $params_emp = $request->all();
184 184
185 $params_job["job_title_id"] = $params_emp['job_title_id']; 185 $params_job["job_title_id"] = $params_emp['job_title_id'];
186 //$params_job["min_salary"] = $params_emp['min_salary']; 186 //$params_job["min_salary"] = $params_emp['min_salary'];
187 //$params_job["max_salary"] = $params_emp['max_salary']; 187 //$params_job["max_salary"] = $params_emp['max_salary'];
188 //$params_job["region"] = $params_emp['region']; 188 //$params_job["region"] = $params_emp['region'];
189 //$params_job["power"] = $params_emp['power']; 189 //$params_job["power"] = $params_emp['power'];
190 //$params_job["sytki"] = $params_emp['sytki']; 190 //$params_job["sytki"] = $params_emp['sytki'];
191 //$params_job["start"] = $params_emp['start']; 191 //$params_job["start"] = $params_emp['start'];
192 //$params_job["flot"] = $params_emp['flot']; 192 //$params_job["flot"] = $params_emp['flot'];
193 //$params_job["description"] = $params_emp['description']; 193 //$params_job["description"] = $params_emp['description'];
194 194
195 $ad_jobs = Ad_employer::create($params_emp); 195 $ad_jobs = Ad_employer::create($params_emp);
196 //$params_job['ad_employer_id'] = $ad_jobs->id; 196 //$params_job['ad_employer_id'] = $ad_jobs->id;
197 //Ad_jobs::create($params_job); 197 //Ad_jobs::create($params_job);
198 $ad_jobs->jobs()->sync($request->get('job_title_id')); 198 $ad_jobs->jobs()->sync($request->get('job_title_id'));
199 199
200 return redirect()->route('employer.vacancy_list'); 200 return redirect()->route('employer.vacancy_list');
201 } 201 }
202 202
203 // Список вакансий 203 // Список вакансий
204 public function vacancy_list(Request $request) { 204 public function vacancy_list(Request $request) {
205 $id = Auth()->user()->id; 205 $id = Auth()->user()->id;
206 206
207 //dd($request->all()); 207 //dd($request->all());
208 $Employer = Employer::query()->where('user_id', $id)->first(); 208 $Employer = Employer::query()->where('user_id', $id)->first();
209 $vacancy_list = Ad_employer::query()->with('jobs')-> 209 $vacancy_list = Ad_employer::query()->with('jobs')->
210 with('jobs_code')-> 210 with('jobs_code')->
211 where('employer_id', $Employer->id); 211 where('employer_id', $Employer->id);
212 212
213 if (($request->has('search')) && (!empty($request->get('search')))) { 213 if (($request->has('search')) && (!empty($request->get('search')))) {
214 $search = $request->get('search'); 214 $search = $request->get('search');
215 $vacancy_list = $vacancy_list->where('name', 'LIKE', "%$search%"); 215 $vacancy_list = $vacancy_list->where('name', 'LIKE', "%$search%");
216 } 216 }
217 217
218 if ($request->get('sort')) { 218 if ($request->get('sort')) {
219 $sort = $request->get('sort'); 219 $sort = $request->get('sort');
220 switch ($sort) { 220 switch ($sort) {
221 case 'name_up': $vacancy_list = $vacancy_list->orderBy('name')->orderBy('id'); break; 221 case 'name_up': $vacancy_list = $vacancy_list->orderBy('name')->orderBy('id'); break;
222 case 'name_down': $vacancy_list = $vacancy_list->orderByDesc('name')->orderby('id'); break; 222 case 'name_down': $vacancy_list = $vacancy_list->orderByDesc('name')->orderby('id'); break;
223 case 'nopublic': $vacancy_list->where('active_is', '=', 0)->orderBy('id');break; 223 case 'nopublic': $vacancy_list->where('active_is', '=', 0)->orderBy('id');break;
224 case 'public':$vacancy_list->where('active_is', '=', 1)->orderBy('id');break; 224 case 'public':$vacancy_list->where('active_is', '=', 1)->orderBy('id');break;
225 case 'created_at_up': $vacancy_list = $vacancy_list->OrderBy('created_at')->orderBy('id'); break; 225 case 'created_at_up': $vacancy_list = $vacancy_list->OrderBy('created_at')->orderBy('id'); break;
226 case 'created_at_down': $vacancy_list = $vacancy_list->orderByDesc('created_at')->orderBy('id'); break; 226 case 'created_at_down': $vacancy_list = $vacancy_list->orderByDesc('created_at')->orderBy('id'); break;
227 case 'default': $vacancy_list = $vacancy_list->orderbyDesc('updated_at')->orderBy('name'); break; 227 case 'default': $vacancy_list = $vacancy_list->orderbyDesc('updated_at')->orderBy('name'); break;
228 default: $vacancy_list = $vacancy_list->orderByDesc('id')->orderbyDesc('updated_at'); break; 228 default: $vacancy_list = $vacancy_list->orderByDesc('id')->orderbyDesc('updated_at'); break;
229 } 229 }
230 } else { 230 } else {
231 $vacancy_list = $vacancy_list->orderByDesc('created_at')->orderBy('id'); 231 $vacancy_list = $vacancy_list->orderByDesc('updated_at')->orderBy('id');
232 } 232 }
233 233
234 $vacancy_list = $vacancy_list->paginate(10); 234 $vacancy_list = $vacancy_list->paginate(10);
235 235
236 //ajax 236 //ajax
237 if ($request->ajax()) { 237 if ($request->ajax()) {
238 return view('employers.ajax.list_vacancy', compact('vacancy_list', 'Employer')); 238 return view('employers.ajax.list_vacancy', compact('vacancy_list', 'Employer'));
239 } else { 239 } else {
240 return view('employers.list_vacancy', compact('vacancy_list', 'Employer')); 240 return view('employers.list_vacancy', compact('vacancy_list', 'Employer'));
241 } 241 }
242 } 242 }
243 243
244 // Карточка вакансии 244 // Карточка вакансии
245 public function vacancy_edit(Ad_employer $ad_employer) { 245 public function vacancy_edit(Ad_employer $ad_employer) {
246 $id = Auth()->user()->id; 246 $id = Auth()->user()->id;
247 $Positions = Category::query()->where('is_remove', '=', '0')->get(); 247 $Positions = Category::query()->where('is_remove', '=', '0')->get();
248 248
249 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 249 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
250 where('is_remove', '=', '0')-> 250 where('is_remove', '=', '0')->
251 where('is_bd', '=', '0')->get(); 251 where('is_bd', '=', '0')->get();
252 252
253 $Employer = Employer::query()->with('users')->with('ads')-> 253 $Employer = Employer::query()->with('users')->with('ads')->
254 with('flots')->where('user_id', $id)->first(); 254 with('flots')->where('user_id', $id)->first();
255 255
256 return view('employers.edit_vacancy', compact('ad_employer', 'Positions','Employer', 'jobs')); 256 return view('employers.edit_vacancy', compact('ad_employer', 'Positions','Employer', 'jobs'));
257 } 257 }
258 258
259 // Сохранение-редактирование записи 259 // Сохранение-редактирование записи
260 public function vacancy_save_me(VacancyRequestEdit $request, Ad_employer $ad_employer) { 260 public function vacancy_save_me(VacancyRequestEdit $request, Ad_employer $ad_employer) {
261 $params = $request->all(); 261 $params = $request->all();
262 $params_job["job_title_id"] = $params['job_title_id']; 262 $params_job["job_title_id"] = $params['job_title_id'];
263 263
264 $ad_employer->update($params); 264 $ad_employer->update($params);
265 $ad_employer->jobs()->sync($request->get('job_title_id')); 265 $ad_employer->jobs()->sync($request->get('job_title_id'));
266 266
267 $id = Auth()->user()->id; 267 $id = Auth()->user()->id;
268 $Positions = Category::query()->where('is_remove', '=', '0')->get(); 268 $Positions = Category::query()->where('is_remove', '=', '0')->get();
269 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name') 269 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')
270 ->where('is_remove', '=', '0') 270 ->where('is_remove', '=', '0')
271 ->where('is_bd', '=', '0') 271 ->where('is_bd', '=', '0')
272 ->get(); 272 ->get();
273 273
274 $Employer = Employer::query() 274 $Employer = Employer::query()
275 ->with('users')->with('ads')->with('flots')->where('user_id', $id)->first(); 275 ->with('users')->with('ads')->with('flots')->where('user_id', $id)->first();
276 return view('employers.edit_vacancy', compact('ad_employer', 'Positions','Employer', 'jobs')); 276 return view('employers.edit_vacancy', compact('ad_employer', 'Positions','Employer', 'jobs'));
277 } 277 }
278 278
279 // Сохранение карточки вакансии 279 // Сохранение карточки вакансии
280 public function vacancy_save(Request $request, Ad_employer $ad_employer) { 280 public function vacancy_save(Request $request, Ad_employer $ad_employer) {
281 $all = $request->all(); 281 $all = $request->all();
282 $ad_employer->update($all); 282 $ad_employer->update($all);
283 return redirect()->route('employer.cabinet_vacancie'); 283 return redirect()->route('employer.cabinet_vacancie');
284 } 284 }
285 285
286 // Удаление карточки вакансии 286 // Удаление карточки вакансии
287 public function vacancy_delete(Ad_employer $ad_employer) { 287 public function vacancy_delete(Ad_employer $ad_employer) {
288 $ad_employer->delete(); 288 $ad_employer->delete();
289 289
290 return redirect()->route('employer.vacancy_list') 290 return redirect()->route('employer.vacancy_list')
291 ->with('success', 'Данные были успешно сохранены'); 291 ->with('success', 'Данные были успешно сохранены');
292 } 292 }
293 293
294 // Обновление даты 294 // Обновление даты
295 public function vacancy_up(Ad_employer $ad_employer) { 295 public function vacancy_up(Ad_employer $ad_employer) {
296 $up = date('m/d/Y h:i:s', time());; 296 $up = date('m/d/Y h:i:s', time());;
297 $vac_emp = Ad_employer::findOrFail($ad_employer->id); 297 $vac_emp = Ad_employer::findOrFail($ad_employer->id);
298 $vac_emp->updated_at = $up; 298 $vac_emp->updated_at = $up;
299 $vac_emp->save(); 299 $vac_emp->save();
300 300
301 return redirect()->back(); //route('employer.vacancy_list'); 301 return redirect()->back(); //route('employer.vacancy_list');
302 // начало конца 302 // начало конца
303 } 303 }
304 304
305 //Видимость вакансии 305 //Видимость вакансии
306 public function vacancy_eye(Ad_employer $ad_employer, $status) { 306 public function vacancy_eye(Ad_employer $ad_employer, $status) {
307 $vac_emp = Ad_employer::findOrFail($ad_employer->id); 307 $vac_emp = Ad_employer::findOrFail($ad_employer->id);
308 $vac_emp->active_is = $status; 308 $vac_emp->active_is = $status;
309 $vac_emp->save(); 309 $vac_emp->save();
310 310
311 return redirect()->route('employer.vacancy_list'); 311 return redirect()->route('employer.vacancy_list');
312 } 312 }
313 313
314 //Вакансия редактирования (шаблон) 314 //Вакансия редактирования (шаблон)
315 public function vacancy_update(Ad_employer $id) { 315 public function vacancy_update(Ad_employer $id) {
316 316
317 } 317 }
318 318
319 //Отклики на вакансию - лист 319 //Отклики на вакансию - лист
320 public function answers(Employer $employer, Request $request) { 320 public function answers(Employer $employer, Request $request) {
321 $user_id = Auth()->user()->id; 321 $user_id = Auth()->user()->id;
322 $answer = Ad_employer::query()->where('employer_id', $employer->id); 322 $answer = Ad_employer::query()->where('employer_id', $employer->id);
323 if ($request->has('search')) { 323 if ($request->has('search')) {
324 $search = trim($request->get('search')); 324 $search = trim($request->get('search'));
325 if (!empty($search)) $answer = $answer->where('name', 'LIKE', "%$search%"); 325 if (!empty($search)) $answer = $answer->where('name', 'LIKE', "%$search%");
326 } 326 }
327 327
328 $answer = $answer->with('response')->OrderByDESC('id')->get(); 328 $answer = $answer->with('response')->OrderByDESC('id')->get();
329 329
330 return view('employers.list_answer', compact('answer', 'user_id', 'employer')); 330 return view('employers.list_answer', compact('answer', 'user_id', 'employer'));
331 } 331 }
332 332
333 //Обновление статуса 333 //Обновление статуса
334 public function supple_status(employer $employer, ad_response $ad_response, $flag) { 334 public function supple_status(employer $employer, ad_response $ad_response, $flag) {
335 $ad_response->update(Array('flag' => $flag)); 335 $ad_response->update(Array('flag' => $flag));
336 return redirect()->route('employer.answers', ['employer' => $employer->id]); 336 return redirect()->route('employer.answers', ['employer' => $employer->id]);
337 } 337 }
338 338
339 //Страницы сообщений список 339 //Страницы сообщений список
340 public function messages($type_message) { 340 public function messages($type_message) {
341 $user_id = Auth()->user()->id; 341 $user_id = Auth()->user()->id;
342 342
343 $chats = Chat::get_user_chats($user_id); 343 $chats = Chat::get_user_chats($user_id);
344 $user_type = 'employer'; 344 $user_type = 'employer';
345 345
346 return view('employers.messages', compact('chats','user_id', 'user_type')); 346 return view('employers.messages', compact('chats','user_id', 'user_type'));
347 } 347 }
348 348
349 // Диалог между пользователями 349 // Диалог между пользователями
350 public function dialog(Request $request, User_Model $user1, User_Model $user2) { 350 public function dialog(Request $request, User_Model $user1, User_Model $user2) {
351 // Получение параметров. 351 // Получение параметров.
352 if ($request->has('ad_employer')){ 352 if ($request->has('ad_employer')){
353 $ad_employer = $request->get('ad_employer'); 353 $ad_employer = $request->get('ad_employer');
354 } else { 354 } else {
355 $ad_employer = 0; 355 $ad_employer = 0;
356 } 356 }
357 357
358 if (isset($user2->id)) { 358 if (isset($user2->id)) {
359 $companion = User_Model::query()->with('workers')-> 359 $companion = User_Model::query()->with('workers')->
360 with('employers')-> 360 with('employers')->
361 where('id', $user2->id)->first(); 361 where('id', $user2->id)->first();
362 } 362 }
363 363
364 $Messages = Message::query() 364 $Messages = Message::query()
365 ->where(function($query) use ($user1, $user2) { 365 ->where(function($query) use ($user1, $user2) {
366 $query->where('user_id', $user1->id)->where('to_user_id', $user2->id); 366 $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
367 }) 367 })
368 ->orWhere(function($query) use ($user1, $user2) { 368 ->orWhere(function($query) use ($user1, $user2) {
369 $query->where('user_id', $user2->id)->where('to_user_id', $user1->id); 369 $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
370 }) 370 })
371 ->orderBy('created_at') 371 ->orderBy('created_at')
372 ->get() 372 ->get()
373 ; 373 ;
374 374
375 $sender = $user1; 375 $sender = $user1;
376 376
377 Message::where('user_id', '=', $user2->id) 377 Message::where('user_id', '=', $user2->id)
378 ->where('to_user_id', '=', $user1->id) 378 ->where('to_user_id', '=', $user1->id)
379 ->update(['flag_new' => 0]) 379 ->update(['flag_new' => 0])
380 ; 380 ;
381 381
382 return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages')); 382 return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages'));
383 } 383 }
384 384
385 public function pin_chat(Request $request){ 385 public function pin_chat(Request $request){
386 $chat_id = $request->get('id'); 386 $chat_id = $request->get('id');
387 $is_fixed = $request->get('is_fixed'); 387 $is_fixed = $request->get('is_fixed');
388 388
389 Chat::pin_chat($chat_id, $is_fixed); 389 Chat::pin_chat($chat_id, $is_fixed);
390 } 390 }
391 391
392 public function remove_chat(Request $request){ 392 public function remove_chat(Request $request){
393 $chat_id = $request->get('id'); 393 $chat_id = $request->get('id');
394 Chat::remove_chat($chat_id); 394 Chat::remove_chat($chat_id);
395 } 395 }
396 396
397 // Регистрация работодателя 397 // Регистрация работодателя
398 public function register_employer(Request $request) { 398 public function register_employer(Request $request) {
399 $params = $request->all(); 399 $params = $request->all();
400 400
401 $rules = [ 401 $rules = [
402 //'surname' => ['required', 'string', 'max:255'], 402 //'surname' => ['required', 'string', 'max:255'],
403 //'name_man' => ['required', 'string', 'max:255'], 403 //'name_man' => ['required', 'string', 'max:255'],
404 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 404 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
405 'name_company' => ['required', 'string', 'max:255'], 405 'name_company' => ['required', 'string', 'max:255'],
406 'password' => ['required', 'string', 'min:6'], 406 'password' => ['required', 'string', 'min:6'],
407 ]; 407 ];
408 408
409 409
410 $messages = [ 410 $messages = [
411 'required' => 'Укажите обязательное поле', 411 'required' => 'Укажите обязательное поле',
412 'min' => [ 412 'min' => [
413 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 413 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
414 'integer' => 'Поле «:attribute» должно быть :min или больше', 414 'integer' => 'Поле «:attribute» должно быть :min или больше',
415 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 415 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
416 ], 416 ],
417 'max' => [ 417 'max' => [
418 'string' => 'Поле «:attribute» должно быть не больше :max символов', 418 'string' => 'Поле «:attribute» должно быть не больше :max символов',
419 'integer' => 'Поле «:attribute» должно быть :max или меньше', 419 'integer' => 'Поле «:attribute» должно быть :max или меньше',
420 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 420 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
421 ] 421 ]
422 ]; 422 ];
423 423
424 $email = $request->get('email'); 424 $email = $request->get('email');
425 if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) { 425 if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) {
426 return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл")); 426 return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл"));
427 } 427 }
428 428
429 if ($request->get('password') !== $request->get('confirmed')){ 429 if ($request->get('password') !== $request->get('confirmed')){
430 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); 430 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля"));
431 } 431 }
432 432
433 if (strlen($request->get('password')) < 6) { 433 if (strlen($request->get('password')) < 6) {
434 return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); 434 return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!"));
435 } 435 }
436 436
437 if (empty($request->get('surname'))) { 437 if (empty($request->get('surname'))) {
438 $params['surname'] = 'Неизвестно'; 438 $params['surname'] = 'Неизвестно';
439 } 439 }
440 if (empty($request->get('name_man'))) { 440 if (empty($request->get('name_man'))) {
441 $params['name_man'] = 'Неизвестно'; 441 $params['name_man'] = 'Неизвестно';
442 } 442 }
443 $validator = Validator::make($params, $rules, $messages); 443 $validator = Validator::make($params, $rules, $messages);
444 444
445 if ($validator->fails()) { 445 if ($validator->fails()) {
446 return json_encode(Array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); 446 return json_encode(Array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе."));
447 } else { 447 } else {
448 $user = $this->create($params); 448 $user = $this->create($params);
449 event(new Registered($user)); 449 event(new Registered($user));
450 450
451 Mail::to(env('EMAIL_ADMIN'))->send(new MailCreateEmployer($params)); 451 Mail::to(env('EMAIL_ADMIN'))->send(new MailCreateEmployer($params));
452 452
453 Auth::guard()->login($user); 453 Auth::guard()->login($user);
454 } 454 }
455 455
456 if ($user) { 456 if ($user) {
457 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));; 457 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));;
458 } else { 458 } else {
459 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!")); 459 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!"));
460 } 460 }
461 } 461 }
462 462
463 // Создание пользователя 463 // Создание пользователя
464 protected function create(array $data) 464 protected function create(array $data)
465 { 465 {
466 $Use = new User_Model(); 466 $Use = new User_Model();
467 $Code_user = $Use->create([ 467 $Code_user = $Use->create([
468 'name' => $data['surname']." ".$data['name_man'], 468 'name' => $data['surname']." ".$data['name_man'],
469 'name_man' => $data['name_man'], 469 'name_man' => $data['name_man'],
470 'surname' => $data['surname'], 470 'surname' => $data['surname'],
471 'surname2' => $data['surname2'], 471 'surname2' => $data['surname2'],
472 'subscribe_email' => $data['email'], 472 'subscribe_email' => $data['email'],
473 'email' => $data['email'], 473 'email' => $data['email'],
474 'telephone' => $data['telephone'], 474 'telephone' => $data['telephone'],
475 'is_worker' => 0, 475 'is_worker' => 0,
476 'password' => Hash::make($data['password']), 476 'password' => Hash::make($data['password']),
477 'pubpassword' => base64_encode($data['password']), 477 'pubpassword' => base64_encode($data['password']),
478 'email_verified_at' => Carbon::now() 478 'email_verified_at' => Carbon::now()
479 ]); 479 ]);
480 480
481 if ($Code_user->id > 0) { 481 if ($Code_user->id > 0) {
482 $Employer = new Employer(); 482 $Employer = new Employer();
483 $Employer->user_id = $Code_user->id; 483 $Employer->user_id = $Code_user->id;
484 $Employer->name_company = $data['name_company']; 484 $Employer->name_company = $data['name_company'];
485 $Employer->email = $data['email']; 485 $Employer->email = $data['email'];
486 $Employer->telephone = $data['telephone']; 486 $Employer->telephone = $data['telephone'];
487 $Employer->code = Tools::generator_id(10); 487 $Employer->code = Tools::generator_id(10);
488 $Employer->save(); 488 $Employer->save();
489 489
490 return $Code_user; 490 return $Code_user;
491 } 491 }
492 } 492 }
493 493
494 // Отправка сообщения от работодателя 494 // Отправка сообщения от работодателя
495 public function send_message(MessagesRequiest $request) { 495 public function send_message(MessagesRequiest $request) {
496 $params = $request->all(); 496 $params = $request->all();
497 dd($params); 497 dd($params);
498 $user1 = $params['user_id']; 498 $user1 = $params['user_id'];
499 $user2 = $params['to_user_id']; 499 $user2 = $params['to_user_id'];
500 500
501 if ($request->has('file')) { 501 if ($request->has('file')) {
502 $params['file'] = $request->file('file')->store("messages", 'public'); 502 $params['file'] = $request->file('file')->store("messages", 'public');
503 } 503 }
504 Message::create($params); 504 Message::create($params);
505 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 505 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
506 } 506 }
507 507
508 public function test123(Request $request) { 508 public function test123(Request $request) {
509 $params = $request->all(); 509 $params = $request->all();
510 $user1 = $params['user_id']; 510 $user1 = $params['user_id'];
511 $user2 = $params['to_user_id']; 511 $user2 = $params['to_user_id'];
512 $id_vacancy = $params['ad_employer_id']; 512 $id_vacancy = $params['ad_employer_id'];
513 $ad_name = $params['ad_name']; 513 $ad_name = $params['ad_name'];
514 514
515 $rules = [ 515 $rules = [
516 'text' => 'required|min:1|max:150000', 516 'text' => 'required|min:1|max:150000',
517 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' 517 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000'
518 ]; 518 ];
519 $messages = [ 519 $messages = [
520 'required' => 'Укажите обязательное поле', 520 'required' => 'Укажите обязательное поле',
521 'min' => [ 521 'min' => [
522 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 522 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
523 'integer' => 'Поле «:attribute» должно быть :min или больше', 523 'integer' => 'Поле «:attribute» должно быть :min или больше',
524 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 524 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
525 ], 525 ],
526 'max' => [ 526 'max' => [
527 'string' => 'Поле «:attribute» должно быть не больше :max символов', 527 'string' => 'Поле «:attribute» должно быть не больше :max символов',
528 'integer' => 'Поле «:attribute» должно быть :max или меньше', 528 'integer' => 'Поле «:attribute» должно быть :max или меньше',
529 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 529 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
530 ] 530 ]
531 ]; 531 ];
532 532
533 $validator = Validator::make($request->all(), $rules, $messages); 533 $validator = Validator::make($request->all(), $rules, $messages);
534 534
535 /*if ($validator->fails()) { 535 /*if ($validator->fails()) {
536 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]) 536 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2])
537 ->withErrors($validator); 537 ->withErrors($validator);
538 } else { 538 } else {
539 if ($request->has('file')) { 539 if ($request->has('file')) {
540 $params['file'] = $request->file('file')->store("messages", 'public'); 540 $params['file'] = $request->file('file')->store("messages", 'public');
541 } 541 }
542 Message::create($params); 542 Message::create($params);
543 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 543 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
544 return redirect()->route('employer.dialog', 544 return redirect()->route('employer.dialog',
545 ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]); 545 ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]);
546 546
547 }*/ 547 }*/
548 548
549 if ($validator->fails()) { 549 if ($validator->fails()) {
550 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]) 550 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2])
551 ->withErrors($validator); 551 ->withErrors($validator);
552 } else { 552 } else {
553 Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); 553 Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
554 554
555 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 555 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
556 return redirect()->route('employer.dialog', 556 return redirect()->route('employer.dialog',
557 ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]); 557 ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]);
558 558
559 } 559 }
560 } 560 }
561 561
562 //Избранные люди 562 //Избранные люди
563 public function favorites(Request $request) { 563 public function favorites(Request $request) {
564 $IP_address = RusDate::ip_addr_client(); 564 $IP_address = RusDate::ip_addr_client();
565 $Arr = Like_worker::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get(); 565 $Arr = Like_worker::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get();
566 566
567 if ($Arr->count()) { 567 if ($Arr->count()) {
568 $A = Array(); 568 $A = Array();
569 foreach ($Arr as $it) { 569 foreach ($Arr as $it) {
570 $A[] = $it->code_record; 570 $A[] = $it->code_record;
571 } 571 }
572 572
573 $Workers = Worker::query()->whereIn('id', $A); 573 $Workers = Worker::query()->whereIn('id', $A);
574 } else { 574 } else {
575 $Workers = Worker::query()->where('id', '=', '0'); 575 $Workers = Worker::query()->where('id', '=', '0');
576 } 576 }
577 577
578 if (($request->has('search')) && (!empty($request->get('search')))) { 578 if (($request->has('search')) && (!empty($request->get('search')))) {
579 $search = $request->get('search'); 579 $search = $request->get('search');
580 580
581 $Workers = $Workers->WhereHas('users', 581 $Workers = $Workers->WhereHas('users',
582 function (Builder $query) use ($search) { 582 function (Builder $query) use ($search) {
583 $query->Where('surname', 'LIKE', "%$search%") 583 $query->Where('surname', 'LIKE', "%$search%")
584 ->orWhere('name_man', 'LIKE', "%$search%") 584 ->orWhere('name_man', 'LIKE', "%$search%")
585 ->orWhere('surname2', 'LIKE', "%$search%"); 585 ->orWhere('surname2', 'LIKE', "%$search%");
586 }); 586 });
587 } else { 587 } else {
588 $Workers = $Workers->with('users'); 588 $Workers = $Workers->with('users');
589 } 589 }
590 590
591 $Workers = $Workers->get(); 591 $Workers = $Workers->get();
592 592
593 593
594 return view('employers.favorite', compact('Workers')); 594 return view('employers.favorite', compact('Workers'));
595 } 595 }
596 596
597 // База данных 597 // База данных
598 public function bd(Request $request) { 598 public function bd(Request $request) {
599 $users = User_Model::query()->with('workers')->with('jobtitles'); 599 $users = User_Model::query()->with('workers')->with('jobtitles');
600 600
601 if ($request->has('search')) { 601 if ($request->has('search')) {
602 $find_key = $request->get('search'); 602 $find_key = $request->get('search');
603 $users = $users->where('name', 'LIKE', "%$find_key%") 603 $users = $users->where('name', 'LIKE', "%$find_key%")
604 ->orWhere('surname', 'LIKE', "%$find_key%") 604 ->orWhere('surname', 'LIKE', "%$find_key%")
605 ->orWhere('name_man', 'LIKE', "%$find_key%") 605 ->orWhere('name_man', 'LIKE', "%$find_key%")
606 ->orWhere('email', 'LIKE', "%$find_key%") 606 ->orWhere('email', 'LIKE', "%$find_key%")
607 ->orWhere('telephone', 'LIKE', "%$find_key%"); 607 ->orWhere('telephone', 'LIKE', "%$find_key%");
608 } 608 }
609 609
610 // Данные 610 // Данные
611 $users = $users->Baseuser()-> 611 $users = $users->Baseuser()->
612 orderByDesc(Worker::select('created_at')->whereColumn('workers.user_id', 'users.id')); 612 orderByDesc(Worker::select('created_at')->whereColumn('workers.user_id', 'users.id'));
613 $count_users = $users; 613 $count_users = $users;
614 $users = $users->paginate(5); 614 $users = $users->paginate(5);
615 615
616 $export_options = DbExportColumns::toArray(); 616 $export_options = DbExportColumns::toArray();
617 617
618 $jobs_titles = Job_title::select('id', 'name') 618 $jobs_titles = Job_title::select('id', 'name')
619 ->where('is_remove', '=', 0) 619 ->where('is_remove', '=', 0)
620 ->where('is_bd', '=', 2) 620 ->where('is_bd', '=', 2)
621 ->orderByDesc('sort') 621 ->orderByDesc('sort')
622 ->orderBy('name', 'asc') 622 ->orderBy('name', 'asc')
623 ->get() 623 ->get()
624 ->toArray() 624 ->toArray()
625 ; 625 ;
626 626
627 return view('employers.bd', compact('users', 'count_users', 'export_options', 'jobs_titles')); 627 return view('employers.bd', compact('users', 'count_users', 'export_options', 'jobs_titles'));
628 } 628 }
629 629
630 //Настройка уведомлений 630 //Настройка уведомлений
631 public function subscribe() { 631 public function subscribe() {
632 return view('employers.subcribe'); 632 return view('employers.subcribe');
633 } 633 }
634 634
635 //Установка уведомлений сохранение 635 //Установка уведомлений сохранение
636 public function save_subscribe(Request $request) { 636 public function save_subscribe(Request $request) {
637 dd($request->all()); 637 dd($request->all());
638 $msg = $request->validate([ 638 $msg = $request->validate([
639 'subscribe_email' => 'required|email|min:5|max:255', 639 'subscribe_email' => 'required|email|min:5|max:255',
640 ]); 640 ]);
641 return redirect()->route('employer.subscribe')->with('Вы успешно подписались на рассылку'); 641 return redirect()->route('employer.subscribe')->with('Вы успешно подписались на рассылку');
642 } 642 }
643 643
644 //Сбросить форму с паролем 644 //Сбросить форму с паролем
645 public function password_reset() { 645 public function password_reset() {
646 $email = Auth()->user()->email; 646 $email = Auth()->user()->email;
647 return view('employers.password-reset', compact('email')); 647 return view('employers.password-reset', compact('email'));
648 } 648 }
649 649
650 //Обновление пароля 650 //Обновление пароля
651 public function new_password(Request $request) { 651 public function new_password(Request $request) {
652 $use = Auth()->user(); 652 $use = Auth()->user();
653 $request->validate([ 653 $request->validate([
654 'password' => 'required|string', 654 'password' => 'required|string',
655 'new_password' => 'required|string', 655 'new_password' => 'required|string',
656 'new_password2' => 'required|string' 656 'new_password2' => 'required|string'
657 ]); 657 ]);
658 658
659 if ($request->get('new_password') == $request->get('new_password2')) 659 if ($request->get('new_password') == $request->get('new_password2'))
660 if ($request->get('password') !== $request->get('new_password')) { 660 if ($request->get('password') !== $request->get('new_password')) {
661 $credentials = $request->only('email', 'password'); 661 $credentials = $request->only('email', 'password');
662 if (Auth::attempt($credentials)) { 662 if (Auth::attempt($credentials)) {
663 663
664 if (!is_null($use->email_verified_at)){ 664 if (!is_null($use->email_verified_at)){
665 665
666 $user_data = User_Model::find($use->id); 666 $user_data = User_Model::find($use->id);
667 $user_data->update([ 667 $user_data->update([
668 'password' => Hash::make($request->get('new_password')), 668 'password' => Hash::make($request->get('new_password')),
669 'pubpassword' => base64_encode($request->get('new_password')), 669 'pubpassword' => base64_encode($request->get('new_password')),
670 ]); 670 ]);
671 return redirect() 671 return redirect()
672 ->route('employer.password_reset') 672 ->route('employer.password_reset')
673 ->with('success', 'Поздравляю! Вы обновили свой пароль!'); 673 ->with('success', 'Поздравляю! Вы обновили свой пароль!');
674 } 674 }
675 675
676 return redirect() 676 return redirect()
677 ->route('employer.password_reset') 677 ->route('employer.password_reset')
678 ->withError('Данная учетная запись не было верифицированна!'); 678 ->withError('Данная учетная запись не было верифицированна!');
679 } 679 }
680 } 680 }
681 681
682 return redirect() 682 return redirect()
683 ->route('employer.password_reset') 683 ->route('employer.password_reset')
684 ->withErrors('Не совпадение данных, обновите пароли!'); 684 ->withErrors('Не совпадение данных, обновите пароли!');
685 } 685 }
686 686
687 687
688 688
689 // Форма Удаление пипла 689 // Форма Удаление пипла
690 public function delete_people() { 690 public function delete_people() {
691 $login = Auth()->user()->email; 691 $login = Auth()->user()->email;
692 return view('employers.delete_people', compact('login')); 692 return view('employers.delete_people', compact('login'));
693 } 693 }
694 694
695 // Удаление аккаунта 695 // Удаление аккаунта
696 public function action_delete_user(Request $request) { 696 public function action_delete_user(Request $request) {
697 $Answer = $request->all(); 697 $Answer = $request->all();
698 $user_id = Auth()->user()->id; 698 $user_id = Auth()->user()->id;
699 $request->validate([ 699 $request->validate([
700 'password' => 'required|string', 700 'password' => 'required|string',
701 ]); 701 ]);
702 702
703 $credentials = $request->only('email', 'password'); 703 $credentials = $request->only('email', 'password');
704 if (Auth::attempt($credentials)) { 704 if (Auth::attempt($credentials)) {
705 Auth::logout(); 705 Auth::logout();
706 $it = User_Model::find($user_id); 706 $it = User_Model::find($user_id);
707 $it->delete(); 707 $it->delete();
708 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); 708 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
709 } else { 709 } else {
710 return redirect()->route('employer.delete_people') 710 return redirect()->route('employer.delete_people')
711 ->withErrors( 'Неверный пароль! Нужен корректный пароль'); 711 ->withErrors( 'Неверный пароль! Нужен корректный пароль');
712 } 712 }
713 } 713 }
714 714
715 public function ajax_delete_user(Request $request) { 715 public function ajax_delete_user(Request $request) {
716 $Answer = $request->all(); 716 $Answer = $request->all();
717 $user_id = Auth()->user()->id; 717 $user_id = Auth()->user()->id;
718 $request->validate([ 718 $request->validate([
719 'password' => 'required|string', 719 'password' => 'required|string',
720 ]); 720 ]);
721 $credentials = $request->only('email', 'password'); 721 $credentials = $request->only('email', 'password');
722 if (Auth::attempt($credentials)) { 722 if (Auth::attempt($credentials)) {
723 723
724 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт', 724 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт',
725 'email' => $request->get('email'), 725 'email' => $request->get('email'),
726 'password' => $request->get('password'))); 726 'password' => $request->get('password')));
727 } else { 727 } else {
728 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль')); 728 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль'));
729 } 729 }
730 } 730 }
731 731
732 // FAQ - Вопросы/ответы для работодателей и соискателей 732 // FAQ - Вопросы/ответы для работодателей и соискателей
733 public function faq() { 733 public function faq() {
734 return view('employers.faq'); 734 return view('employers.faq');
735 } 735 }
736 736
737 // Рассылка сообщений 737 // Рассылка сообщений
738 public function send_all_messages() { 738 public function send_all_messages() {
739 $id = Auth()->user()->id; 739 $id = Auth()->user()->id;
740 $sending = Employer::query()->where('user_id', '=', "$id")->first(); 740 $sending = Employer::query()->where('user_id', '=', "$id")->first();
741 741
742 if ($sending->sending_is) 742 if ($sending->sending_is)
743 return view('employers.send_all'); 743 return view('employers.send_all');
744 else 744 else
745 return view('employers.send_all_danger'); 745 return view('employers.send_all_danger');
746 } 746 }
747 747
748 // Отправка сообщений для информации 748 // Отправка сообщений для информации
749 public function send_all_post(Request $request) { 749 public function send_all_post(Request $request) {
750 $data = $request->all(); 750 $data = $request->all();
751 751
752 $emails = User_Model::query()->where('is_worker', '1')->get(); 752 $emails = User_Model::query()->where('is_worker', '1')->get();
753 753
754 foreach ($emails as $e) { 754 foreach ($emails as $e) {
755 Mail::to($e->email)->send(new SendAllMessages($data)); 755 Mail::to($e->email)->send(new SendAllMessages($data));
756 } 756 }
757 757
758 return redirect()->route('employer.send_all_messages')->with('success', 'Письма были отправлены'); 758 return redirect()->route('employer.send_all_messages')->with('success', 'Письма были отправлены');
759 } 759 }
760 760
761 // База резюме 761 // База резюме
762 public function bd_tupe(Request $request) { 762 public function bd_tupe(Request $request) {
763 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get(); 763 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get();
764 764
765 return view('employers.bd_tupe', compact('Resume')); 765 return view('employers.bd_tupe', compact('Resume'));
766 } 766 }
767 767
768 ////////////////////////////////////////////////////////////////// 768 //////////////////////////////////////////////////////////////////
769 // Отправил сообщение 769 // Отправил сообщение
770 ////////////////////////////////////////////////////////////////// 770 //////////////////////////////////////////////////////////////////
771 public function new_message(Request $request) { 771 public function new_message(Request $request) {
772 $params = $request->all(); 772 $params = $request->all();
773 773
774 $id = $params['_user_id']; 774 $id = $params['_user_id'];
775 $message_params = [ 775 $message_params = [
776 'title' => $params['title'], 776 'title' => $params['title'],
777 'text' => $params['text'], 777 'text' => $params['text'],
778 'ad_employer_id' => $params['_vacancy'], 778 'ad_employer_id' => $params['_vacancy'],
779 'flag_new' => 1 779 'flag_new' => 1
780 ]; 780 ];
781 781
782 Message::add_message( 782 Message::add_message(
783 $request, 783 $request,
784 $params['_user_id'], 784 $params['_user_id'],
785 $params['_to_user_id'], 785 $params['_to_user_id'],
786 $message_params, 786 $message_params,
787 file_store_path: "worker/$id" 787 file_store_path: "worker/$id"
788 ); 788 );
789 789
790 return redirect()->route('employer.messages', ['type_message' => 'output']); 790 return redirect()->route('employer.messages', ['type_message' => 'output']);
791 } 791 }
792 792
793 // Восстановление пароля 793 // Восстановление пароля
794 public function repair_password(Request $request) { 794 public function repair_password(Request $request) {
795 $params = $request->get('email'); 795 $params = $request->get('email');
796 } 796 }
797 797
798 // Избранные люди на корабль 798 // Избранные люди на корабль
799 public function selected_people(Request $request) { 799 public function selected_people(Request $request) {
800 $id = $request->get('id'); 800 $id = $request->get('id');
801 $favorite_people = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 801 $favorite_people = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
802 where('is_remove', '=', '0')-> 802 where('is_remove', '=', '0')->
803 where('is_bd', '=', '0')-> 803 where('is_bd', '=', '0')->
804 where('position_id', $id)-> 804 where('position_id', $id)->
805 get(); 805 get();
806 return view('favorite_people', compact('favorite_people')); 806 return view('favorite_people', compact('favorite_people'));
807 } 807 }
808 } 808 }
809 809