Commit df58eaf866f733375eba98bc3a72d72644792f6d

Authored by Сергей П
1 parent 4a58df1ed3
Exists in master

правки

Showing 6 changed files with 27 additions and 14 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\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\MassSendingMessages; 13 use App\Mail\MassSendingMessages;
14 use App\Mail\SendAllMessages; 14 use App\Mail\SendAllMessages;
15 use App\Models\Ad_employer; 15 use App\Models\Ad_employer;
16 use App\Models\ad_response; 16 use App\Models\ad_response;
17 use App\Models\Category; 17 use App\Models\Category;
18 use App\Models\Chat; 18 use App\Models\Chat;
19 use App\Models\Employer; 19 use App\Models\Employer;
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_worker; 22 use App\Models\Like_worker;
23 use App\Models\Message; 23 use App\Models\Message;
24 use App\Models\Worker; 24 use App\Models\Worker;
25 use App\Models\MessagesRequests; 25 use App\Models\MessagesRequests;
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\Http\Request; 29 use Illuminate\Http\Request;
30 use Illuminate\Support\Facades\Auth; 30 use Illuminate\Support\Facades\Auth;
31 use Illuminate\Support\Facades\Hash; 31 use Illuminate\Support\Facades\Hash;
32 use Illuminate\Support\Facades\Mail; 32 use Illuminate\Support\Facades\Mail;
33 use Illuminate\Support\Facades\Storage; 33 use Illuminate\Support\Facades\Storage;
34 use App\Models\User as User_Model; 34 use App\Models\User as User_Model;
35 use Illuminate\Support\Facades\Validator; 35 use Illuminate\Support\Facades\Validator;
36 use App\Enums\DbExportColumns; 36 use App\Enums\DbExportColumns;
37 37
38 class EmployerController extends Controller 38 class EmployerController extends Controller
39 { 39 {
40 public function vacancie($vacancy, Request $request) { 40 public function vacancie($vacancy, Request $request) {
41 $title = 'Заголовок вакансии'; 41 $title = 'Заголовок вакансии';
42 $Query = Ad_employer::with('jobs')-> 42 $Query = Ad_employer::with('jobs')->
43 with('cat')-> 43 with('cat')->
44 with('employer')-> 44 with('employer')->
45 with('jobs_code')-> 45 with('jobs_code')->
46 select('ad_employers.*')-> 46 select('ad_employers.*')->
47 where('id', '=', $vacancy)->get(); 47 where('id', '=', $vacancy)->get();
48 48
49 if (isset(Auth()->user()->id)) 49 if (isset(Auth()->user()->id))
50 $uid = Auth()->user()->id; 50 $uid = Auth()->user()->id;
51 else 51 else
52 $uid = 0; 52 $uid = 0;
53 $title = $Query[0]->name; 53 $title = $Query[0]->name;
54 if ($request->ajax()) { 54 if ($request->ajax()) {
55 return view('ajax.vacance-item', compact('Query','uid')); 55 return view('ajax.vacance-item', compact('Query','uid'));
56 } else { 56 } else {
57 return view('vacance-item', compact('title', 'Query', 'uid')); 57 return view('vacance-item', compact('title', 'Query', 'uid'));
58 } 58 }
59 } 59 }
60 60
61 public function logout() { 61 public function logout() {
62 Auth::logout(); 62 Auth::logout();
63 return redirect()->route('index') 63 return redirect()->route('index')
64 ->with('success', 'Вы вышли из личного кабинета'); 64 ->with('success', 'Вы вышли из личного кабинета');
65 } 65 }
66 66
67 public function employer_info() { 67 public function employer_info() {
68 // код юзера 68 // код юзера
69 $user_info = Auth()->user(); 69 $user_info = Auth()->user();
70 // вьюшка для вывода данных 70 // вьюшка для вывода данных
71 return view('employers.info', compact('user_info')); 71 return view('employers.info', compact('user_info'));
72 } 72 }
73 73
74 public function employer_info_save(User_Model $user, BaseUser_min_Request $request) { 74 public function employer_info_save(User_Model $user, BaseUser_min_Request $request) {
75 // Все данные через реквест 75 // Все данные через реквест
76 $all = $request->all(); 76 $all = $request->all();
77 unset($all['_token']); 77 unset($all['_token']);
78 // обновление 78 // обновление
79 $user->update($all); 79 $user->update($all);
80 return redirect()->route('employer.employer_info'); 80 return redirect()->route('employer.employer_info');
81 } 81 }
82 82
83 public function cabinet() { 83 public function cabinet() {
84 $id = Auth()->user()->id; 84 $id = Auth()->user()->id;
85 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 85 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
86 WhereHas('users', 86 WhereHas('users',
87 function (Builder $query) use ($id) {$query->Where('id', $id); 87 function (Builder $query) use ($id) {$query->Where('id', $id);
88 })->get(); 88 })->get();
89 return view('employers.cabinet45', compact('Employer')); 89 return view('employers.cabinet45', compact('Employer'));
90 } 90 }
91 91
92 public function slider_flot() { 92 public function slider_flot() {
93 $id = Auth()->user()->id; 93 $id = Auth()->user()->id;
94 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 94 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
95 WhereHas('users', 95 WhereHas('users',
96 function (Builder $query) use ($id) {$query->Where('id', $id); 96 function (Builder $query) use ($id) {$query->Where('id', $id);
97 })->get(); 97 })->get();
98 return view('employers.fly-flot', compact('Employer')); 98 return view('employers.fly-flot', compact('Employer'));
99 } 99 }
100 100
101 public function cabinet_save(Employer $Employer, Request $request) { 101 public function cabinet_save(Employer $Employer, Request $request) {
102 $params = $request->all(); 102 $params = $request->all();
103 $params['user_id'] = Auth()->user()->id; 103 $params['user_id'] = Auth()->user()->id;
104 $id = $Employer->id; 104 $id = $Employer->id;
105 105
106 if ($request->has('logo')) { 106 if ($request->has('logo')) {
107 if (!empty($Employer->logo)) { 107 if (!empty($Employer->logo)) {
108 Storage::delete($Employer->logo); 108 Storage::delete($Employer->logo);
109 } 109 }
110 $params['logo'] = $request->file('logo')->store("employer/$id", 'public'); 110 $params['logo'] = $request->file('logo')->store("employer/$id", 'public');
111 } 111 }
112 112
113 $Employer->update($params); 113 $Employer->update($params);
114 114
115 return redirect()->route('employer.cabinet')->with('success', 'Данные были успешно сохранены'); 115 return redirect()->route('employer.cabinet')->with('success', 'Данные были успешно сохранены');
116 } 116 }
117 117
118 public function save_add_flot(FlotRequest $request) { 118 public function save_add_flot(FlotRequest $request) {
119 // отмена 119 // отмена
120 $params = $request->all(); 120 $params = $request->all();
121 121
122 if ($request->has('image')) { 122 if ($request->has('image')) {
123 $params['image'] = $request->file('image')->store("flot", 'public'); 123 $params['image'] = $request->file('image')->store("flot", 'public');
124 } 124 }
125 Flot::create($params); 125 Flot::create($params);
126 $data_flots = Flot::query()->where('employer_id', $request->get('employer_if'))->get(); 126 $data_flots = Flot::query()->where('employer_id', $request->get('employer_if'))->get();
127 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен'); 127 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен');
128 } 128 }
129 129
130 public function edit_flot(Flot $Flot, Employer $Employer) { 130 public function edit_flot(Flot $Flot, Employer $Employer) {
131 return view('employers.edit-flot', compact('Flot', 'Employer')); 131 return view('employers.edit-flot', compact('Flot', 'Employer'));
132 } 132 }
133 133
134 public function update_flot(FlotRequest $request, Flot $Flot) { 134 public function update_flot(FlotRequest $request, Flot $Flot) {
135 $params = $request->all(); 135 $params = $request->all();
136 136
137 if ($request->has('image')) { 137 if ($request->has('image')) {
138 if (!empty($flot->image)) { 138 if (!empty($flot->image)) {
139 Storage::delete($flot->image); 139 Storage::delete($flot->image);
140 } 140 }
141 $params['image'] = $request->file('image')->store("flot", 'public'); 141 $params['image'] = $request->file('image')->store("flot", 'public');
142 } else { 142 } else {
143 if (!empty($flot->image)) $params['image'] = $flot->image; 143 if (!empty($flot->image)) $params['image'] = $flot->image;
144 } 144 }
145 145
146 $Flot->update($params); 146 $Flot->update($params);
147 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен'); 147 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен');
148 } 148 }
149 149
150 public function delete_flot(Flot $Flot) { 150 public function delete_flot(Flot $Flot) {
151 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get(); 151 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get();
152 152
153 if (isset($Flot->id)) $Flot->delete(); 153 if (isset($Flot->id)) $Flot->delete();
154 return redirect()->route('employer.slider_flot')->with('success', 'Корабль был удален'); 154 return redirect()->route('employer.slider_flot')->with('success', 'Корабль был удален');
155 } 155 }
156 156
157 // Форма добавления вакансий 157 // Форма добавления вакансий
158 public function cabinet_vacancie() { 158 public function cabinet_vacancie() {
159 $id = Auth()->user()->id; 159 $id = Auth()->user()->id;
160 160
161 if (Auth()->user()->is_public) { 161 if (Auth()->user()->is_public) {
162 $categories = Category::query()->active()->get(); 162 $categories = Category::query()->active()->get();
163 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 163 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
164 where('is_remove', '=', '0')-> 164 where('is_remove', '=', '0')->
165 where('is_bd', '=', '0')-> 165 where('is_bd', '=', '0')->
166 get(); 166 get();
167 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 167 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
168 WhereHas('users', 168 WhereHas('users',
169 function (Builder $query) use ($id) { 169 function (Builder $query) use ($id) {
170 $query->Where('id', $id); 170 $query->Where('id', $id);
171 })->get(); 171 })->get();
172 return view('employers.add_vacancy', compact('Employer', 'jobs', 'categories')); 172 return view('employers.add_vacancy', compact('Employer', 'jobs', 'categories'));
173 } else { 173 } else {
174 return redirect()->route('employer.cabinet_vacancie_danger'); 174 return redirect()->route('employer.cabinet_vacancie_danger');
175 } 175 }
176 } 176 }
177 177
178 // Форма предупреждения об оплате 178 // Форма предупреждения об оплате
179 public function cabinet_vacancie_danger() { 179 public function cabinet_vacancie_danger() {
180 return view('employers.add_vacancy_danger'); 180 return view('employers.add_vacancy_danger');
181 } 181 }
182 182
183 // Сохранение вакансии 183 // Сохранение вакансии
184 public function cabinet_vacancy_save1(VacancyRequestEdit $request) { 184 public function cabinet_vacancy_save1(VacancyRequestEdit $request) {
185 $params_emp = $request->all(); 185 $params_emp = $request->all();
186 186
187 $params_job["job_title_id"] = $params_emp['job_title_id']; 187 $params_job["job_title_id"] = $params_emp['job_title_id'];
188 //$params_job["min_salary"] = $params_emp['min_salary']; 188 //$params_job["min_salary"] = $params_emp['min_salary'];
189 //$params_job["max_salary"] = $params_emp['max_salary']; 189 //$params_job["max_salary"] = $params_emp['max_salary'];
190 //$params_job["region"] = $params_emp['region']; 190 //$params_job["region"] = $params_emp['region'];
191 //$params_job["power"] = $params_emp['power']; 191 //$params_job["power"] = $params_emp['power'];
192 //$params_job["sytki"] = $params_emp['sytki']; 192 //$params_job["sytki"] = $params_emp['sytki'];
193 //$params_job["start"] = $params_emp['start']; 193 //$params_job["start"] = $params_emp['start'];
194 //$params_job["flot"] = $params_emp['flot']; 194 //$params_job["flot"] = $params_emp['flot'];
195 //$params_job["description"] = $params_emp['description']; 195 //$params_job["description"] = $params_emp['description'];
196 196
197 $ad_jobs = Ad_employer::create($params_emp); 197 $ad_jobs = Ad_employer::create($params_emp);
198 //$params_job['ad_employer_id'] = $ad_jobs->id; 198 //$params_job['ad_employer_id'] = $ad_jobs->id;
199 //Ad_jobs::create($params_job); 199 //Ad_jobs::create($params_job);
200 $ad_jobs->jobs()->sync($request->get('job_title_id')); 200 $ad_jobs->jobs()->sync($request->get('job_title_id'));
201 201
202 return redirect()->route('employer.vacancy_list'); 202 return redirect()->route('employer.vacancy_list');
203 } 203 }
204 204
205 // Список вакансий 205 // Список вакансий
206 public function vacancy_list(Request $request) { 206 public function vacancy_list(Request $request) {
207 $id = Auth()->user()->id; 207 $id = Auth()->user()->id;
208 208
209 //dd($request->all()); 209 //dd($request->all());
210 $Employer = Employer::query()->where('user_id', $id)->first(); 210 $Employer = Employer::query()->where('user_id', $id)->first();
211 $vacancy_list = Ad_employer::query()->with('jobs')-> 211 $vacancy_list = Ad_employer::query()->with('jobs')->
212 with('jobs_code')-> 212 with('jobs_code')->
213 where('employer_id', $Employer->id); 213 where('employer_id', $Employer->id);
214 214
215 if (($request->has('search')) && (!empty($request->get('search')))) { 215 if (($request->has('search')) && (!empty($request->get('search')))) {
216 $search = $request->get('search'); 216 $search = $request->get('search');
217 $vacancy_list = $vacancy_list->where('name', 'LIKE', "%$search%"); 217 $vacancy_list = $vacancy_list->where('name', 'LIKE', "%$search%");
218 } 218 }
219 219
220 if ($request->get('sort')) { 220 if ($request->get('sort')) {
221 $sort = $request->get('sort'); 221 $sort = $request->get('sort');
222 switch ($sort) { 222 switch ($sort) {
223 case 'name_up': $vacancy_list = $vacancy_list->orderBy('name')->orderBy('id'); break; 223 case 'name_up': $vacancy_list = $vacancy_list->orderBy('name')->orderBy('id'); break;
224 case 'name_down': $vacancy_list = $vacancy_list->orderByDesc('name')->orderby('id'); break; 224 case 'name_down': $vacancy_list = $vacancy_list->orderByDesc('name')->orderby('id'); break;
225 case 'nopublic': $vacancy_list->where('active_is', '=', 0)->orderBy('id');break; 225 case 'nopublic': $vacancy_list->where('active_is', '=', 0)->orderBy('id');break;
226 case 'public':$vacancy_list->where('active_is', '=', 1)->orderBy('id');break; 226 case 'public':$vacancy_list->where('active_is', '=', 1)->orderBy('id');break;
227 case 'created_at_up': $vacancy_list = $vacancy_list->OrderBy('created_at')->orderBy('id'); break; 227 case 'created_at_up': $vacancy_list = $vacancy_list->OrderBy('created_at')->orderBy('id'); break;
228 case 'created_at_down': $vacancy_list = $vacancy_list->orderByDesc('created_at')->orderBy('id'); break; 228 case 'created_at_down': $vacancy_list = $vacancy_list->orderByDesc('created_at')->orderBy('id'); break;
229 case 'default': $vacancy_list = $vacancy_list->orderbyDesc('updated_at')->orderBy('name'); break; 229 case 'default': $vacancy_list = $vacancy_list->orderbyDesc('updated_at')->orderBy('name'); break;
230 default: $vacancy_list = $vacancy_list->orderByDesc('id')->orderbyDesc('updated_at'); break; 230 default: $vacancy_list = $vacancy_list->orderByDesc('id')->orderbyDesc('updated_at'); break;
231 } 231 }
232 } else { 232 } else {
233 $vacancy_list = $vacancy_list->orderByDesc('updated_at')->orderBy('id'); 233 $vacancy_list = $vacancy_list->orderByDesc('updated_at')->orderBy('id');
234 } 234 }
235 235
236 $vacancy_list = $vacancy_list->paginate(10); 236 $vacancy_list = $vacancy_list->paginate(10);
237 237
238 //ajax 238 //ajax
239 if ($request->ajax()) { 239 if ($request->ajax()) {
240 return view('employers.ajax.list_vacancy', compact('vacancy_list', 'Employer')); 240 return view('employers.ajax.list_vacancy', compact('vacancy_list', 'Employer'));
241 } else { 241 } else {
242 return view('employers.list_vacancy', compact('vacancy_list', 'Employer')); 242 return view('employers.list_vacancy', compact('vacancy_list', 'Employer'));
243 } 243 }
244 } 244 }
245 245
246 // Карточка вакансии 246 // Карточка вакансии
247 public function vacancy_edit(Ad_employer $ad_employer) { 247 public function vacancy_edit(Ad_employer $ad_employer) {
248 $id = Auth()->user()->id; 248 $id = Auth()->user()->id;
249 $Positions = Category::query()->where('is_remove', '=', '0')->get(); 249 $Positions = Category::query()->where('is_remove', '=', '0')->get();
250 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 250 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
251 where('is_remove', '=', '0')-> 251 where('is_remove', '=', '0')->
252 where('is_bd', '=', '0')->get(); 252 where('is_bd', '=', '0')->get();
253 253
254 $Employer = Employer::query()->with('users')->with('ads')-> 254 $Employer = Employer::query()->with('users')->with('ads')->
255 with('flots')->where('user_id', $id)->first(); 255 with('flots')->where('user_id', $id)->first();
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 $admin_chat = false; 345 $admin_chat = false;
346 346
347 return view('employers.messages', compact('chats', 'admin_chat', 'user_id', 'user_type')); 347 return view('employers.messages', compact('chats', 'admin_chat', 'user_id', 'user_type'));
348 } 348 }
349 349
350 // Диалог между пользователями 350 // Диалог между пользователями
351 public function dialog(Chat $chat, Request $request) { 351 public function dialog(Chat $chat, Request $request) {
352 // Получение параметров. 352 // Получение параметров.
353 if ($request->has('ad_employer')){ 353 if ($request->has('ad_employer')){
354 $ad_employer = $request->get('ad_employer'); 354 $ad_employer = $request->get('ad_employer');
355 } else { 355 } else {
356 $ad_employer = 0; 356 $ad_employer = 0;
357 } 357 }
358 358
359 $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first(); 359 $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first();
360 $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first(); 360 $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first();
361 361
362 $Messages = Chat::get_chat_messages($chat); 362 $Messages = Chat::get_chat_messages($chat);
363 363
364 Message::where('user_id', '=', $chat->to_user_id)->where('to_user_id', '=', $chat->user_id)->update(['flag_new' => 0]); 364 Message::where('user_id', '=', $chat->to_user_id)->where('to_user_id', '=', $chat->user_id)->update(['flag_new' => 0]);
365 365
366 return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages')); 366 return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages'));
367 } 367 }
368 368
369 public function pin_chat(Request $request){ 369 public function pin_chat(Request $request){
370 $chat_id = $request->get('id'); 370 $chat_id = $request->get('id');
371 $is_fixed = $request->get('is_fixed'); 371 $is_fixed = $request->get('is_fixed');
372 372
373 Chat::pin_chat($chat_id, $is_fixed); 373 Chat::pin_chat($chat_id, $is_fixed);
374 } 374 }
375 375
376 public function remove_chat(Request $request){ 376 public function remove_chat(Request $request){
377 $chat_id = $request->get('id'); 377 $chat_id = $request->get('id');
378 Chat::remove_chat($chat_id); 378 Chat::remove_chat($chat_id);
379 } 379 }
380 380
381 // Регистрация работодателя 381 // Регистрация работодателя
382 public function register_employer(Request $request) { 382 public function register_employer(Request $request) {
383 $params = $request->all(); 383 $params = $request->all();
384 384
385 $rules = [ 385 $rules = [
386 //'surname' => ['required', 'string', 'max:255'], 386 //'surname' => ['required', 'string', 'max:255'],
387 //'name_man' => ['required', 'string', 'max:255'], 387 //'name_man' => ['required', 'string', 'max:255'],
388 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 388 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
389 'name_company' => ['required', 'string', 'max:255'], 389 'name_company' => ['required', 'string', 'max:255'],
390 'password' => ['required', 'string', 'min:6'], 390 'password' => ['required', 'string', 'min:6'],
391 ]; 391 ];
392 392
393 393
394 $messages = [ 394 $messages = [
395 'required' => 'Укажите обязательное поле', 395 'required' => 'Укажите обязательное поле',
396 'min' => [ 396 'min' => [
397 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 397 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
398 'integer' => 'Поле «:attribute» должно быть :min или больше', 398 'integer' => 'Поле «:attribute» должно быть :min или больше',
399 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 399 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
400 ], 400 ],
401 'max' => [ 401 'max' => [
402 'string' => 'Поле «:attribute» должно быть не больше :max символов', 402 'string' => 'Поле «:attribute» должно быть не больше :max символов',
403 'integer' => 'Поле «:attribute» должно быть :max или меньше', 403 'integer' => 'Поле «:attribute» должно быть :max или меньше',
404 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 404 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
405 ] 405 ]
406 ]; 406 ];
407 407
408 $email = $request->get('email'); 408 $email = $request->get('email');
409 if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) { 409 if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) {
410 return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл")); 410 return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл"));
411 } 411 }
412 412
413 if ($request->get('password') !== $request->get('confirmed')){ 413 if ($request->get('password') !== $request->get('confirmed')){
414 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); 414 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля"));
415 } 415 }
416 416
417 if (strlen($request->get('password')) < 6) { 417 if (strlen($request->get('password')) < 6) {
418 return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); 418 return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!"));
419 } 419 }
420 420
421 if (empty($request->get('surname'))) { 421 if (empty($request->get('surname'))) {
422 $params['surname'] = 'Неизвестно'; 422 $params['surname'] = 'Неизвестно';
423 } 423 }
424 if (empty($request->get('name_man'))) { 424 if (empty($request->get('name_man'))) {
425 $params['name_man'] = 'Неизвестно'; 425 $params['name_man'] = 'Неизвестно';
426 } 426 }
427 $validator = Validator::make($params, $rules, $messages); 427 $validator = Validator::make($params, $rules, $messages);
428 428
429 if ($validator->fails()) { 429 if ($validator->fails()) {
430 return json_encode(Array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); 430 return json_encode(Array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе."));
431 } else { 431 } else {
432 $user = $this->create($params); 432 $user = $this->create($params);
433 event(new Registered($user)); 433 event(new Registered($user));
434 434
435 Mail::to(env('EMAIL_ADMIN'))->send(new MailCreateEmployer($params)); 435 Mail::to(env('EMAIL_ADMIN'))->send(new MailCreateEmployer($params));
436 436
437 Auth::guard()->login($user); 437 Auth::guard()->login($user);
438 } 438 }
439 439
440 if ($user) { 440 if ($user) {
441 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));; 441 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));;
442 } else { 442 } else {
443 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!")); 443 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!"));
444 } 444 }
445 } 445 }
446 446
447 // Создание пользователя 447 // Создание пользователя
448 protected function create(array $data) 448 protected function create(array $data)
449 { 449 {
450 $Use = new User_Model(); 450 $Use = new User_Model();
451 $Code_user = $Use->create([ 451 $Code_user = $Use->create([
452 'name' => $data['surname']." ".$data['name_man'], 452 'name' => $data['surname']." ".$data['name_man'],
453 'name_man' => $data['name_man'], 453 'name_man' => $data['name_man'],
454 'surname' => $data['surname'], 454 'surname' => $data['surname'],
455 'surname2' => $data['surname2'], 455 'surname2' => $data['surname2'],
456 'subscribe_email' => $data['email'], 456 'subscribe_email' => $data['email'],
457 'email' => $data['email'], 457 'email' => $data['email'],
458 'telephone' => $data['telephone'], 458 'telephone' => $data['telephone'],
459 'is_worker' => 0, 459 'is_worker' => 0,
460 'password' => Hash::make($data['password']), 460 'password' => Hash::make($data['password']),
461 'pubpassword' => base64_encode($data['password']), 461 'pubpassword' => base64_encode($data['password']),
462 'email_verified_at' => Carbon::now() 462 'email_verified_at' => Carbon::now()
463 ]); 463 ]);
464 464
465 if ($Code_user->id > 0) { 465 if ($Code_user->id > 0) {
466 $Employer = new Employer(); 466 $Employer = new Employer();
467 $Employer->user_id = $Code_user->id; 467 $Employer->user_id = $Code_user->id;
468 $Employer->name_company = $data['name_company']; 468 $Employer->name_company = $data['name_company'];
469 $Employer->email = $data['email']; 469 $Employer->email = $data['email'];
470 $Employer->telephone = $data['telephone']; 470 $Employer->telephone = $data['telephone'];
471 $Employer->code = Tools::generator_id(10); 471 $Employer->code = Tools::generator_id(10);
472 $Employer->save(); 472 $Employer->save();
473 473
474 return $Code_user; 474 return $Code_user;
475 } 475 }
476 } 476 }
477 477
478 // Отправка сообщения от работодателя 478 // Отправка сообщения от работодателя
479 public function send_message(MessagesRequiest $request) { 479 public function send_message(MessagesRequiest $request) {
480 $params = $request->all(); 480 $params = $request->all();
481 dd($params); 481 dd($params);
482 $user1 = $params['user_id']; 482 $user1 = $params['user_id'];
483 $user2 = $params['to_user_id']; 483 $user2 = $params['to_user_id'];
484 484
485 if ($request->has('file')) { 485 if ($request->has('file')) {
486 $params['file'] = $request->file('file')->store("messages", 'public'); 486 $params['file'] = $request->file('file')->store("messages", 'public');
487 } 487 }
488 Message::create($params); 488 Message::create($params);
489 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 489 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
490 } 490 }
491 491
492 public function test123(Request $request) { 492 public function test123(Request $request) {
493 $params = $request->all(); 493 $params = $request->all();
494 $user1 = $params['user_id']; 494 $user1 = $params['user_id'];
495 $user2 = $params['to_user_id']; 495 $user2 = $params['to_user_id'];
496 $id_vacancy = $params['ad_employer_id']; 496 $id_vacancy = $params['ad_employer_id'];
497 $ad_name = $params['ad_name']; 497 $ad_name = $params['ad_name'];
498 498
499 $rules = [ 499 $rules = [
500 'text' => 'required|min:1|max:150000', 500 'text' => 'required|min:1|max:150000',
501 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' 501 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000'
502 ]; 502 ];
503 $messages = [ 503 $messages = [
504 'required' => 'Укажите обязательное поле', 504 'required' => 'Укажите обязательное поле',
505 'min' => [ 505 'min' => [
506 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 506 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
507 'integer' => 'Поле «:attribute» должно быть :min или больше', 507 'integer' => 'Поле «:attribute» должно быть :min или больше',
508 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 508 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
509 ], 509 ],
510 'max' => [ 510 'max' => [
511 'string' => 'Поле «:attribute» должно быть не больше :max символов', 511 'string' => 'Поле «:attribute» должно быть не больше :max символов',
512 'integer' => 'Поле «:attribute» должно быть :max или меньше', 512 'integer' => 'Поле «:attribute» должно быть :max или меньше',
513 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 513 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
514 ] 514 ]
515 ]; 515 ];
516 516
517 $validator = Validator::make($request->all(), $rules, $messages); 517 $validator = Validator::make($request->all(), $rules, $messages);
518 518
519 /*if ($validator->fails()) { 519 /*if ($validator->fails()) {
520 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]) 520 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2])
521 ->withErrors($validator); 521 ->withErrors($validator);
522 } else { 522 } else {
523 if ($request->has('file')) { 523 if ($request->has('file')) {
524 $params['file'] = $request->file('file')->store("messages", 'public'); 524 $params['file'] = $request->file('file')->store("messages", 'public');
525 } 525 }
526 Message::create($params); 526 Message::create($params);
527 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 527 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
528 return redirect()->route('employer.dialog', 528 return redirect()->route('employer.dialog',
529 ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]); 529 ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]);
530 530
531 }*/ 531 }*/
532 532
533 if ($validator->fails()) { 533 if ($validator->fails()) {
534 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]) 534 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2])
535 ->withErrors($validator); 535 ->withErrors($validator);
536 } else { 536 } else {
537 Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); 537 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
538 538
539 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 539 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
540 return redirect()->route('employer.dialog', 540 return redirect()->route('employer.dialog', ['chat' => $new_message->chat_id_from]);
541 ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]);
542 541
543 } 542 }
544 } 543 }
545 544
546 //Избранные люди 545 //Избранные люди
547 public function favorites(Request $request) { 546 public function favorites(Request $request) {
548 $IP_address = RusDate::ip_addr_client(); 547 $IP_address = RusDate::ip_addr_client();
549 $Arr = Like_worker::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get(); 548 $Arr = Like_worker::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get();
550 549
551 if ($Arr->count()) { 550 if ($Arr->count()) {
552 $A = Array(); 551 $A = Array();
553 foreach ($Arr as $it) { 552 foreach ($Arr as $it) {
554 $A[] = $it->code_record; 553 $A[] = $it->code_record;
555 } 554 }
556 555
557 $Workers = Worker::query()->whereIn('id', $A); 556 $Workers = Worker::query()->whereIn('id', $A);
558 } else { 557 } else {
559 $Workers = Worker::query()->where('id', '=', '0'); 558 $Workers = Worker::query()->where('id', '=', '0');
560 } 559 }
561 560
562 if (($request->has('search')) && (!empty($request->get('search')))) { 561 if (($request->has('search')) && (!empty($request->get('search')))) {
563 $search = $request->get('search'); 562 $search = $request->get('search');
564 563
565 $Workers = $Workers->WhereHas('users', 564 $Workers = $Workers->WhereHas('users',
566 function (Builder $query) use ($search) { 565 function (Builder $query) use ($search) {
567 $query->Where('surname', 'LIKE', "%$search%") 566 $query->Where('surname', 'LIKE', "%$search%")
568 ->orWhere('name_man', 'LIKE', "%$search%") 567 ->orWhere('name_man', 'LIKE', "%$search%")
569 ->orWhere('surname2', 'LIKE', "%$search%"); 568 ->orWhere('surname2', 'LIKE', "%$search%");
570 }); 569 });
571 } else { 570 } else {
572 $Workers = $Workers->with('users'); 571 $Workers = $Workers->with('users');
573 } 572 }
574 573
575 $Workers = $Workers->get(); 574 $Workers = $Workers->get();
576 575
577 576
578 return view('employers.favorite', compact('Workers')); 577 return view('employers.favorite', compact('Workers'));
579 } 578 }
580 579
581 // База данных 580 // База данных
582 public function bd(Request $request) { 581 public function bd(Request $request) {
583 $users = User_Model::query()->with('workers')->with('jobtitles'); 582 $users = User_Model::query()->with('workers')->with('jobtitles');
584 583
585 if ($request->has('search')) { 584 if ($request->has('search')) {
586 $find_key = $request->get('search'); 585 $find_key = $request->get('search');
587 $users = $users->where('name', 'LIKE', "%$find_key%") 586 $users = $users->where('name', 'LIKE', "%$find_key%")
588 ->orWhere('surname', 'LIKE', "%$find_key%") 587 ->orWhere('surname', 'LIKE', "%$find_key%")
589 ->orWhere('name_man', 'LIKE', "%$find_key%") 588 ->orWhere('name_man', 'LIKE', "%$find_key%")
590 ->orWhere('email', 'LIKE', "%$find_key%") 589 ->orWhere('email', 'LIKE', "%$find_key%")
591 ->orWhere('telephone', 'LIKE', "%$find_key%"); 590 ->orWhere('telephone', 'LIKE', "%$find_key%");
592 } 591 }
593 592
594 // Данные 593 // Данные
595 $users = $users->Baseuser()-> 594 $users = $users->Baseuser()->
596 orderByDesc(Worker::select('created_at')->whereColumn('workers.user_id', 'users.id')); 595 orderByDesc(Worker::select('created_at')->whereColumn('workers.user_id', 'users.id'));
597 $count_users = $users; 596 $count_users = $users;
598 $users = $users->paginate(5); 597 $users = $users->paginate(5);
599 598
600 $export_options = DbExportColumns::toArray(); 599 $export_options = DbExportColumns::toArray();
601 600
602 $jobs_titles = Job_title::select('id', 'name') 601 $jobs_titles = Job_title::select('id', 'name')
603 ->where('is_remove', '=', 0) 602 ->where('is_remove', '=', 0)
604 ->where('is_bd', '=', 2) 603 ->where('is_bd', '=', 2)
605 ->orderByDesc('sort') 604 ->orderByDesc('sort')
606 ->orderBy('name', 'asc') 605 ->orderBy('name', 'asc')
607 ->get() 606 ->get()
608 ->toArray() 607 ->toArray()
609 ; 608 ;
610 609
611 return view('employers.bd', compact('users', 'count_users', 'export_options', 'jobs_titles')); 610 return view('employers.bd', compact('users', 'count_users', 'export_options', 'jobs_titles'));
612 } 611 }
613 612
614 //Настройка уведомлений 613 //Настройка уведомлений
615 public function subscribe() { 614 public function subscribe() {
616 return view('employers.subcribe'); 615 return view('employers.subcribe');
617 } 616 }
618 617
619 //Установка уведомлений сохранение 618 //Установка уведомлений сохранение
620 public function save_subscribe(Request $request) { 619 public function save_subscribe(Request $request) {
621 dd($request->all()); 620 dd($request->all());
622 $msg = $request->validate([ 621 $msg = $request->validate([
623 'subscribe_email' => 'required|email|min:5|max:255', 622 'subscribe_email' => 'required|email|min:5|max:255',
624 ]); 623 ]);
625 return redirect()->route('employer.subscribe')->with('Вы успешно подписались на рассылку'); 624 return redirect()->route('employer.subscribe')->with('Вы успешно подписались на рассылку');
626 } 625 }
627 626
628 //Сбросить форму с паролем 627 //Сбросить форму с паролем
629 public function password_reset() { 628 public function password_reset() {
630 $email = Auth()->user()->email; 629 $email = Auth()->user()->email;
631 return view('employers.password-reset', compact('email')); 630 return view('employers.password-reset', compact('email'));
632 } 631 }
633 632
634 //Обновление пароля 633 //Обновление пароля
635 public function new_password(Request $request) { 634 public function new_password(Request $request) {
636 $use = Auth()->user(); 635 $use = Auth()->user();
637 $request->validate([ 636 $request->validate([
638 'password' => 'required|string', 637 'password' => 'required|string',
639 'new_password' => 'required|string', 638 'new_password' => 'required|string',
640 'new_password2' => 'required|string' 639 'new_password2' => 'required|string'
641 ]); 640 ]);
642 641
643 if ($request->get('new_password') == $request->get('new_password2')) 642 if ($request->get('new_password') == $request->get('new_password2'))
644 if ($request->get('password') !== $request->get('new_password')) { 643 if ($request->get('password') !== $request->get('new_password')) {
645 $credentials = $request->only('email', 'password'); 644 $credentials = $request->only('email', 'password');
646 if (Auth::attempt($credentials)) { 645 if (Auth::attempt($credentials)) {
647 646
648 if (!is_null($use->email_verified_at)){ 647 if (!is_null($use->email_verified_at)){
649 648
650 $user_data = User_Model::find($use->id); 649 $user_data = User_Model::find($use->id);
651 $user_data->update([ 650 $user_data->update([
652 'password' => Hash::make($request->get('new_password')), 651 'password' => Hash::make($request->get('new_password')),
653 'pubpassword' => base64_encode($request->get('new_password')), 652 'pubpassword' => base64_encode($request->get('new_password')),
654 ]); 653 ]);
655 return redirect() 654 return redirect()
656 ->route('employer.password_reset') 655 ->route('employer.password_reset')
657 ->with('success', 'Поздравляю! Вы обновили свой пароль!'); 656 ->with('success', 'Поздравляю! Вы обновили свой пароль!');
658 } 657 }
659 658
660 return redirect() 659 return redirect()
661 ->route('employer.password_reset') 660 ->route('employer.password_reset')
662 ->withError('Данная учетная запись не было верифицированна!'); 661 ->withError('Данная учетная запись не было верифицированна!');
663 } 662 }
664 } 663 }
665 664
666 return redirect() 665 return redirect()
667 ->route('employer.password_reset') 666 ->route('employer.password_reset')
668 ->withErrors('Не совпадение данных, обновите пароли!'); 667 ->withErrors('Не совпадение данных, обновите пароли!');
669 } 668 }
670 669
671 670
672 671
673 // Форма Удаление пипла 672 // Форма Удаление пипла
674 public function delete_people() { 673 public function delete_people() {
675 $login = Auth()->user()->email; 674 $login = Auth()->user()->email;
676 return view('employers.delete_people', compact('login')); 675 return view('employers.delete_people', compact('login'));
677 } 676 }
678 677
679 // Удаление аккаунта 678 // Удаление аккаунта
680 public function action_delete_user(Request $request) { 679 public function action_delete_user(Request $request) {
681 $Answer = $request->all(); 680 $Answer = $request->all();
682 $user_id = Auth()->user()->id; 681 $user_id = Auth()->user()->id;
683 $request->validate([ 682 $request->validate([
684 'password' => 'required|string', 683 'password' => 'required|string',
685 ]); 684 ]);
686 685
687 $credentials = $request->only('email', 'password'); 686 $credentials = $request->only('email', 'password');
688 if (Auth::attempt($credentials)) { 687 if (Auth::attempt($credentials)) {
689 Auth::logout(); 688 Auth::logout();
690 $it = User_Model::find($user_id); 689 $it = User_Model::find($user_id);
691 $it->delete(); 690 $it->delete();
692 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); 691 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
693 } else { 692 } else {
694 return redirect()->route('employer.delete_people') 693 return redirect()->route('employer.delete_people')
695 ->withErrors( 'Неверный пароль! Нужен корректный пароль'); 694 ->withErrors( 'Неверный пароль! Нужен корректный пароль');
696 } 695 }
697 } 696 }
698 697
699 public function ajax_delete_user(Request $request) { 698 public function ajax_delete_user(Request $request) {
700 $Answer = $request->all(); 699 $Answer = $request->all();
701 $user_id = Auth()->user()->id; 700 $user_id = Auth()->user()->id;
702 $request->validate([ 701 $request->validate([
703 'password' => 'required|string', 702 'password' => 'required|string',
704 ]); 703 ]);
705 $credentials = $request->only('email', 'password'); 704 $credentials = $request->only('email', 'password');
706 if (Auth::attempt($credentials)) { 705 if (Auth::attempt($credentials)) {
707 706
708 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт', 707 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт',
709 'email' => $request->get('email'), 708 'email' => $request->get('email'),
710 'password' => $request->get('password'))); 709 'password' => $request->get('password')));
711 } else { 710 } else {
712 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль')); 711 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль'));
713 } 712 }
714 } 713 }
715 714
716 // FAQ - Вопросы/ответы для работодателей и соискателей 715 // FAQ - Вопросы/ответы для работодателей и соискателей
717 public function faq() { 716 public function faq() {
718 return view('employers.faq'); 717 return view('employers.faq');
719 } 718 }
720 719
721 // Рассылка сообщений 720 // Рассылка сообщений
722 public function send_all_messages() { 721 public function send_all_messages() {
723 $id = Auth()->user()->id; 722 $id = Auth()->user()->id;
724 $sending = Employer::query()->where('user_id', '=', "$id")->first(); 723 $sending = Employer::query()->where('user_id', '=', "$id")->first();
725 724
726 $job_titles = Job_title::query() 725 $job_titles = Job_title::query()
727 ->where('is_remove', '=', 0) 726 ->where('is_remove', '=', 0)
728 ->where('is_bd', '=', 1) 727 ->where('is_bd', '=', 1)
729 ->orderByDesc('sort') 728 ->orderByDesc('sort')
730 ->get() 729 ->get()
731 ; 730 ;
732 731
733 if ($sending->sending_is) 732 if ($sending->sending_is)
734 return view('employers.send_all', compact('job_titles')); 733 return view('employers.send_all', compact('job_titles'));
735 else 734 else
736 return view('employers.send_all_danger'); 735 return view('employers.send_all_danger');
737 } 736 }
738 737
739 // Отправка сообщений для информации 738 // Отправка сообщений для информации
740 public function send_all_post(Request $request) { 739 public function send_all_post(Request $request) {
741 $data = $request->all(); 740 $data = $request->all();
742 $data['user'] = Auth()->user(); 741 $data['user'] = Auth()->user();
743 742
744 $id = MessagesRequests::create([ 743 $id = MessagesRequests::create([
745 'user_id' => Auth()->user()->id, 744 'user_id' => Auth()->user()->id,
746 'job_titles' => json_encode($data['job_title_ids']), 745 'job_titles' => json_encode($data['job_title_ids']),
747 'text' => $data['message_text'], 746 'text' => $data['message_text'],
748 ]); 747 ]);
749 748
750 if (!empty($id)){ 749 if (!empty($id)){
751 Mail::to(env('EMAIL_ADMIN'))->send(new MassSendingMessages($data)); 750 Mail::to(env('EMAIL_ADMIN'))->send(new MassSendingMessages($data));
752 } 751 }
753 752
754 /*$emails = User_Model::query()->where('is_worker', '1')->get(); 753 /*$emails = User_Model::query()->where('is_worker', '1')->get();
755 754
756 foreach ($emails as $e) { 755 foreach ($emails as $e) {
757 Mail::to($e->email)->send(new SendAllMessages($data)); 756 Mail::to($e->email)->send(new SendAllMessages($data));
758 }*/ 757 }*/
759 758
760 return redirect()->route('employer.send_all_messages')->with('success', 'Запрос на рассылку был успешно отправлен.'); 759 return redirect()->route('employer.send_all_messages')->with('success', 'Запрос на рассылку был успешно отправлен.');
761 } 760 }
762 761
763 // База резюме 762 // База резюме
764 public function bd_tupe(Request $request) { 763 public function bd_tupe(Request $request) {
765 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get(); 764 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get();
766 765
767 return view('employers.bd_tupe', compact('Resume')); 766 return view('employers.bd_tupe', compact('Resume'));
768 } 767 }
769 768
770 ////////////////////////////////////////////////////////////////// 769 //////////////////////////////////////////////////////////////////
771 // Отправил сообщение 770 // Отправил сообщение
772 ////////////////////////////////////////////////////////////////// 771 //////////////////////////////////////////////////////////////////
773 public function new_message(Request $request) { 772 public function new_message(Request $request) {
774 $params = $request->all(); 773 $params = $request->all();
775 774
776 $id = $params['_user_id']; 775 $id = $params['_user_id'];
777 $message_params = [ 776 $message_params = [
778 'title' => $params['title'], 777 'title' => $params['title'],
779 'text' => $params['text'], 778 'text' => $params['text'],
780 'ad_employer_id' => $params['_vacancy'], 779 'ad_employer_id' => $params['_vacancy'],
781 'flag_new' => 1 780 'flag_new' => 1
782 ]; 781 ];
783 782
784 Message::add_message( 783 Message::add_message(
785 $request, 784 $request,
786 $params['_user_id'], 785 $params['_user_id'],
787 $params['_to_user_id'], 786 $params['_to_user_id'],
788 $message_params, 787 $message_params,
789 file_store_path: "worker/$id" 788 file_store_path: "worker/$id"
790 ); 789 );
791 790
792 return redirect()->route('employer.messages', ['type_message' => 'output']); 791 return redirect()->route('employer.messages', ['type_message' => 'output']);
793 } 792 }
794 793
795 // Восстановление пароля 794 // Восстановление пароля
796 public function repair_password(Request $request) { 795 public function repair_password(Request $request) {
797 $params = $request->get('email'); 796 $params = $request->get('email');
798 } 797 }
799 798
800 // Избранные люди на корабль 799 // Избранные люди на корабль
801 public function selected_people(Request $request) { 800 public function selected_people(Request $request) {
802 $id = $request->get('id'); 801 $id = $request->get('id');
803 $favorite_people = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 802 $favorite_people = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
804 where('is_remove', '=', '0')-> 803 where('is_remove', '=', '0')->
805 where('is_bd', '=', '0')-> 804 where('is_bd', '=', '0')->
806 where('position_id', $id)-> 805 where('position_id', $id)->
807 get(); 806 get();
808 return view('favorite_people', compact('favorite_people')); 807 return view('favorite_people', compact('favorite_people'));
809 } 808 }
810 } 809 }
811 810
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\Http\Requests\PrevCompanyRequest; 7 use App\Http\Requests\PrevCompanyRequest;
8 use App\Http\Requests\SertificationRequest; 8 use App\Http\Requests\SertificationRequest;
9 use App\Models\Ad_employer; 9 use App\Models\Ad_employer;
10 use App\Models\ad_response; 10 use App\Models\ad_response;
11 use App\Models\Chat; 11 use App\Models\Chat;
12 use App\Models\Dop_info; 12 use App\Models\Dop_info;
13 use App\Models\infobloks; 13 use App\Models\infobloks;
14 use App\Models\Job_title; 14 use App\Models\Job_title;
15 use App\Models\Like_vacancy; 15 use App\Models\Like_vacancy;
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\PrevCompany; 18 use App\Models\PrevCompany;
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\Title_worker; 22 use App\Models\Title_worker;
23 use App\Models\User; 23 use App\Models\User;
24 use App\Models\User as User_Model; 24 use App\Models\User as User_Model;
25 use App\Models\Worker; 25 use App\Models\Worker;
26 use Barryvdh\DomPDF\Facade\Pdf; 26 use Barryvdh\DomPDF\Facade\Pdf;
27 use Carbon\Carbon; 27 use Carbon\Carbon;
28 use Illuminate\Auth\Events\Registered; 28 use Illuminate\Auth\Events\Registered;
29 use Illuminate\Database\Eloquent\Builder; 29 use Illuminate\Database\Eloquent\Builder;
30 use Illuminate\Http\Request; 30 use Illuminate\Http\Request;
31 use Illuminate\Support\Facades\Auth; 31 use Illuminate\Support\Facades\Auth;
32 use Illuminate\Support\Facades\Hash; 32 use Illuminate\Support\Facades\Hash;
33 use Illuminate\Support\Facades\Storage; 33 use Illuminate\Support\Facades\Storage;
34 use Illuminate\Support\Facades\Validator; 34 use Illuminate\Support\Facades\Validator;
35 use PhpOffice\PhpSpreadsheet\Spreadsheet; 35 use PhpOffice\PhpSpreadsheet\Spreadsheet;
36 use PhpOffice\PhpSpreadsheet\Writer\Xlsx; 36 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
37 use Symfony\Component\HttpFoundation\StreamedResponse; 37 use Symfony\Component\HttpFoundation\StreamedResponse;
38 use App\Enums\DbExportColumns; 38 use App\Enums\DbExportColumns;
39 use App\Enums\WorkerStatuses; 39 use App\Enums\WorkerStatuses;
40 use DateTime; 40 use DateTime;
41 41
42 class WorkerController extends Controller 42 class WorkerController extends Controller
43 { 43 {
44 //профиль 44 //профиль
45 public function profile(Worker $worker) 45 public function profile(Worker $worker)
46 { 46 {
47 $get_date = date('Y.m'); 47 $get_date = date('Y.m');
48 48
49 $c = Static_worker::query()->where('year_month', '=', $get_date) 49 $c = Static_worker::query()->where('year_month', '=', $get_date)
50 ->where('user_id', '=', $worker->users->id) 50 ->where('user_id', '=', $worker->users->id)
51 ->get(); 51 ->get();
52 52
53 if ($c->count() > 0) { 53 if ($c->count() > 0) {
54 $upd = Static_worker::find($c[0]->id); 54 $upd = Static_worker::find($c[0]->id);
55 $upd->lookin = $upd->lookin + 1; 55 $upd->lookin = $upd->lookin + 1;
56 $upd->save(); 56 $upd->save();
57 } else { 57 } else {
58 $crt = new Static_worker(); 58 $crt = new Static_worker();
59 $crt->lookin = 1; 59 $crt->lookin = 1;
60 $crt->year_month = $get_date; 60 $crt->year_month = $get_date;
61 $crt->user_id = $worker->user_id; 61 $crt->user_id = $worker->user_id;
62 $crt->save(); 62 $crt->save();
63 } 63 }
64 64
65 $stat = Static_worker::query()->where('year_month', '=', $get_date) 65 $stat = Static_worker::query()->where('year_month', '=', $get_date)
66 ->where('user_id', '=', $worker->users->id) 66 ->where('user_id', '=', $worker->users->id)
67 ->get(); 67 ->get();
68 68
69 return view('public.workers.profile', compact('worker', 'stat')); 69 return view('public.workers.profile', compact('worker', 'stat'));
70 } 70 }
71 71
72 // лист база резюме 72 // лист база резюме
73 public function bd_resume(Request $request) 73 public function bd_resume(Request $request)
74 { 74 {
75 $look = false; 75 $look = false;
76 $idiot = 0; 76 $idiot = 0;
77 if (isset(Auth()->user()->id)) { 77 if (isset(Auth()->user()->id)) {
78 $idiot = Auth()->user()->id; 78 $idiot = Auth()->user()->id;
79 if ((!Auth()->user()->is_worker) && (Auth()->user()->is_lookin)) 79 if ((!Auth()->user()->is_worker) && (Auth()->user()->is_lookin))
80 $look = true; 80 $look = true;
81 } 81 }
82 82
83 if ($look) { 83 if ($look) {
84 $status_work = WorkerStatuses::getWorkerStatuses(); 84 $status_work = WorkerStatuses::getWorkerStatuses();
85 $resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at');; 85 $resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at');;
86 $resumes = $resumes->whereHas('users', function (Builder $query) { 86 $resumes = $resumes->whereHas('users', function (Builder $query) {
87 $query->Where('is_worker', '=', '1') 87 $query->Where('is_worker', '=', '1')
88 ->Where('is_bd', '=', '0'); 88 ->Where('is_bd', '=', '0');
89 }); 89 });
90 90
91 //dd($request->get('job')); 91 //dd($request->get('job'));
92 if (($request->has('job')) && ($request->get('job') > 0)) { 92 if (($request->has('job')) && ($request->get('job') > 0)) {
93 $resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) { 93 $resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) {
94 $query->Where('job_titles.id', $request->get('job')); 94 $query->Where('job_titles.id', $request->get('job'));
95 }); 95 });
96 } 96 }
97 97
98 $Job_title = Job_title::query()-> 98 $Job_title = Job_title::query()->
99 where('is_remove', '=', '0')-> 99 where('is_remove', '=', '0')->
100 where('is_bd', '=' , '1')-> 100 where('is_bd', '=' , '1')->
101 get(); 101 get();
102 102
103 if ($request->get('sort')) { 103 if ($request->get('sort')) {
104 $sort = $request->get('sort'); 104 $sort = $request->get('sort');
105 switch ($sort) { 105 switch ($sort) {
106 case 'looking_for_work': 106 case 'looking_for_work':
107 $resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value); 107 $resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value);
108 break; 108 break;
109 case 'considering_offers': 109 case 'considering_offers':
110 $resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value); 110 $resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value);
111 break; 111 break;
112 case 'not_looking_for_work': 112 case 'not_looking_for_work':
113 $resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value); 113 $resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value);
114 break; 114 break;
115 } 115 }
116 } 116 }
117 117
118 $res_count = $resumes->count(); 118 $res_count = $resumes->count();
119 //$resumes = $resumes->get(); 119 //$resumes = $resumes->get();
120 $resumes = $resumes->paginate(4); 120 $resumes = $resumes->paginate(4);
121 if ($request->ajax()) { 121 if ($request->ajax()) {
122 // Условия обставлены 122 // Условия обставлены
123 if ($request->has('block') && ($request->get('block') == 1)) { 123 if ($request->has('block') && ($request->get('block') == 1)) {
124 return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count', 'idiot')); 124 return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count', 'idiot'));
125 } 125 }
126 } else { 126 } else {
127 return view('resume', compact('resumes', 'status_work', 'res_count', 'idiot', 'Job_title')); 127 return view('resume', compact('resumes', 'status_work', 'res_count', 'idiot', 'Job_title'));
128 } 128 }
129 } else { 129 } else {
130 return redirect()->route('index')->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]); 130 return redirect()->route('index')->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]);
131 } 131 }
132 } 132 }
133 133
134 public function basic_information(){ 134 public function basic_information(){
135 if (!isset(Auth()->user()->id)) { 135 if (!isset(Auth()->user()->id)) {
136 abort(404); 136 abort(404);
137 } 137 }
138 138
139 $user_id = Auth()->user()->id; 139 $user_id = Auth()->user()->id;
140 140
141 $user = User::query() 141 $user = User::query()
142 ->with('workers') 142 ->with('workers')
143 ->with(['jobtitles' => function ($query) { 143 ->with(['jobtitles' => function ($query) {
144 $query->select('job_titles.id'); 144 $query->select('job_titles.id');
145 }]) 145 }])
146 ->where('id', '=', $user_id) 146 ->where('id', '=', $user_id)
147 ->first(); 147 ->first();
148 $user->workers[0]->job_titles = $user->workers[0]->job_titles->pluck('id')->toArray(); 148 $user->workers[0]->job_titles = $user->workers[0]->job_titles->pluck('id')->toArray();
149 149
150 $job_titles = Job_title::query() 150 $job_titles = Job_title::query()
151 ->where('is_remove', '=', 0) 151 ->where('is_remove', '=', 0)
152 ->where('is_bd', '=', 1) 152 ->where('is_bd', '=', 1)
153 ->orderByDesc('sort') 153 ->orderByDesc('sort')
154 ->get() 154 ->get()
155 ; 155 ;
156 156
157 return view('workers.form_basic_information', compact('user', 'job_titles')); 157 return view('workers.form_basic_information', compact('user', 'job_titles'));
158 } 158 }
159 159
160 public function additional_documents(){ 160 public function additional_documents(){
161 if (!isset(Auth()->user()->id)) { 161 if (!isset(Auth()->user()->id)) {
162 abort(404); 162 abort(404);
163 } 163 }
164 164
165 $user_id = Auth()->user()->id; 165 $user_id = Auth()->user()->id;
166 166
167 $info_blocks = infobloks::query()->OrderBy('name')->get(); 167 $info_blocks = infobloks::query()->OrderBy('name')->get();
168 $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; 168 $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует'];
169 169
170 $worker = Worker::query() 170 $worker = Worker::query()
171 ->with('users') 171 ->with('users')
172 ->with('infobloks') 172 ->with('infobloks')
173 ->WhereHas('users', function (Builder $query) use ($user_id) { 173 ->WhereHas('users', function (Builder $query) use ($user_id) {
174 $query->Where('id', $user_id); 174 $query->Where('id', $user_id);
175 }) 175 })
176 ->first(); 176 ->first();
177 if ($worker->dop_info->count()){ 177 if ($worker->dop_info->count()){
178 $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray(); 178 $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray();
179 } 179 }
180 180
181 return view('workers.form_additional_documents', compact('worker', 'info_blocks', 'additional_document_statuses')); 181 return view('workers.form_additional_documents', compact('worker', 'info_blocks', 'additional_document_statuses'));
182 } 182 }
183 183
184 //Лайк резюме 184 //Лайк резюме
185 public function like_controller() { 185 public function like_controller() {
186 186
187 } 187 }
188 188
189 // анкета соискателя 189 // анкета соискателя
190 public function resume_profile(Worker $worker) 190 public function resume_profile(Worker $worker)
191 { 191 {
192 if (isset(Auth()->user()->id)) { 192 if (isset(Auth()->user()->id)) {
193 $idiot = Auth()->user()->id; 193 $idiot = Auth()->user()->id;
194 } else { 194 } else {
195 $idiot = 0; 195 $idiot = 0;
196 } 196 }
197 197
198 $status_work = WorkerStatuses::getWorkerStatuses(); 198 $status_work = WorkerStatuses::getWorkerStatuses();
199 $Query = Worker::query()->with('users')->with('job_titles') 199 $Query = Worker::query()->with('users')->with('job_titles')
200 ->with('place_worker')->with('sertificate')->with('prev_company') 200 ->with('place_worker')->with('sertificate')->with('prev_company')
201 ->with('infobloks')->with('response'); 201 ->with('infobloks')->with('response');
202 $Query = $Query->where('id', '=', $worker->id); 202 $Query = $Query->where('id', '=', $worker->id);
203 $Query = $Query->get(); 203 $Query = $Query->get();
204 204
205 $get_date = date('Y.m'); 205 $get_date = date('Y.m');
206 206
207 $infoblocks = infobloks::query()->get(); 207 $infoblocks = infobloks::query()->get();
208 208
209 $c = Static_worker::query()->where('year_month', '=', $get_date) 209 $c = Static_worker::query()->where('year_month', '=', $get_date)
210 ->where('user_id', '=', $worker->user_id) 210 ->where('user_id', '=', $worker->user_id)
211 ->get(); 211 ->get();
212 212
213 if ($c->count() > 0) { 213 if ($c->count() > 0) {
214 $upd = Static_worker::find($c[0]->id); 214 $upd = Static_worker::find($c[0]->id);
215 $upd->lookin = $upd->lookin + 1; 215 $upd->lookin = $upd->lookin + 1;
216 $upd->save(); 216 $upd->save();
217 } else { 217 } else {
218 $crt = new Static_worker(); 218 $crt = new Static_worker();
219 $crt->lookin = 1; 219 $crt->lookin = 1;
220 $crt->year_month = $get_date; 220 $crt->year_month = $get_date;
221 $crt->user_id = $worker->user_id; 221 $crt->user_id = $worker->user_id;
222 $status = $crt->save(); 222 $status = $crt->save();
223 } 223 }
224 224
225 $stat = Static_worker::query()->where('year_month', '=', $get_date) 225 $stat = Static_worker::query()->where('year_month', '=', $get_date)
226 ->where('user_id', '=', $worker->user_id) 226 ->where('user_id', '=', $worker->user_id)
227 ->get(); 227 ->get();
228 228
229 return view('worker', compact('Query', 'infoblocks', 'status_work', 'idiot', 'stat')); 229 return view('worker', compact('Query', 'infoblocks', 'status_work', 'idiot', 'stat'));
230 } 230 }
231 231
232 // скачать анкету соискателя 232 // скачать анкету соискателя
233 public function resume_download(Worker $worker) 233 public function resume_download(Worker $worker)
234 { 234 {
235 $status_work = WorkerStatuses::getWorkerStatuses(); 235 $status_work = WorkerStatuses::getWorkerStatuses();
236 $Query = Worker::query()->with('users')->with('job_titles') 236 $Query = Worker::query()->with('users')->with('job_titles')
237 ->with('place_worker')->with('sertificate')->with('prev_company') 237 ->with('place_worker')->with('sertificate')->with('prev_company')
238 ->with('infobloks'); 238 ->with('infobloks');
239 $Query = $Query->where('id', '=', $worker->id); 239 $Query = $Query->where('id', '=', $worker->id);
240 $Query = $Query->get(); 240 $Query = $Query->get();
241 241
242 view()->share('Query',$Query); 242 view()->share('Query',$Query);
243 243
244 $status_work = WorkerStatuses::getWorkerStatuses(); 244 $status_work = WorkerStatuses::getWorkerStatuses();
245 $infoblocks = infobloks::query()->get(); 245 $infoblocks = infobloks::query()->get();
246 246
247 //return view('layout.pdf', compact('Query', 'status_work', 'infoblocks')); 247 //return view('layout.pdf', compact('Query', 'status_work', 'infoblocks'));
248 $pdf = PDF::loadView('layout.pdf', [ 248 $pdf = PDF::loadView('layout.pdf', [
249 'Query' => $Query, 249 'Query' => $Query,
250 'status_work' => $status_work, 250 'status_work' => $status_work,
251 'infoblocks' => $infoblocks 251 'infoblocks' => $infoblocks
252 ])->setPaper('a4', 'landscape'); 252 ])->setPaper('a4', 'landscape');
253 253
254 return $pdf->stream(); 254 return $pdf->stream();
255 } 255 }
256 256
257 public function resume_download_all(Request $request) { 257 public function resume_download_all(Request $request) {
258 $spreadsheet = new Spreadsheet(); 258 $spreadsheet = new Spreadsheet();
259 $sheet = $spreadsheet->getActiveSheet(); 259 $sheet = $spreadsheet->getActiveSheet();
260 260
261 $columnMap = range('A', 'Z'); 261 $columnMap = range('A', 'Z');
262 $columns = []; 262 $columns = [];
263 263
264 foreach (DbExportColumns::toArray() as $key => $value){ 264 foreach (DbExportColumns::toArray() as $key => $value){
265 if ($request->input($key, 0)){ 265 if ($request->input($key, 0)){
266 $sheet->setCellValue("{$columnMap[count($columns)]}1", ucfirst($value)); 266 $sheet->setCellValue("{$columnMap[count($columns)]}1", ucfirst($value));
267 $columns[] = str_replace('__', '.', $key); 267 $columns[] = str_replace('__', '.', $key);
268 } 268 }
269 } 269 }
270 270
271 if (empty($columns)) { 271 if (empty($columns)) {
272 return redirect()->back()->with('error', 'Пожалуйста выберите хотя бы 1 колонку для экспорта.'); 272 return redirect()->back()->with('error', 'Пожалуйста выберите хотя бы 1 колонку для экспорта.');
273 } 273 }
274 274
275 $query = User::select($columns) 275 $query = User::select($columns)
276 ->leftJoin('workers', 'users.id', '=', 'workers.user_id') 276 ->leftJoin('workers', 'users.id', '=', 'workers.user_id')
277 ->leftJoin('job_titles', 'workers.position_work', '=', 'job_titles.id') 277 ->leftJoin('job_titles', 'workers.position_work', '=', 'job_titles.id')
278 ->where('users.is_bd', '=', 1) 278 ->where('users.is_bd', '=', 1)
279 ; 279 ;
280 280
281 $job_title_list = $request->input('job_title_list', []); 281 $job_title_list = $request->input('job_title_list', []);
282 if (!empty($job_title_list)){ 282 if (!empty($job_title_list)){
283 $query->whereIn('job_titles.id', $job_title_list); 283 $query->whereIn('job_titles.id', $job_title_list);
284 } 284 }
285 285
286 $users = $query->get(); 286 $users = $query->get();
287 if ($users->count()){ 287 if ($users->count()){
288 $i = 2; 288 $i = 2;
289 foreach ($users->toArray() as $user){ 289 foreach ($users->toArray() as $user){
290 $j = 0; 290 $j = 0;
291 foreach ($user as $field){ 291 foreach ($user as $field){
292 $sheet->setCellValue("{$columnMap[$j++]}$i", $field); 292 $sheet->setCellValue("{$columnMap[$j++]}$i", $field);
293 } 293 }
294 $i++; 294 $i++;
295 } 295 }
296 } 296 }
297 $writer = new Xlsx($spreadsheet); 297 $writer = new Xlsx($spreadsheet);
298 $fileName = 'DB.xlsx'; 298 $fileName = 'DB.xlsx';
299 299
300 $response = new StreamedResponse(function() use ($writer) { 300 $response = new StreamedResponse(function() use ($writer) {
301 $writer->save('php://output'); 301 $writer->save('php://output');
302 }); 302 });
303 303
304 $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 304 $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
305 $response->headers->set('Content-Disposition', 'attachment;filename="' . $fileName . '"'); 305 $response->headers->set('Content-Disposition', 'attachment;filename="' . $fileName . '"');
306 $response->headers->set('Cache-Control', 'max-age=0'); 306 $response->headers->set('Cache-Control', 'max-age=0');
307 307
308 return $response; 308 return $response;
309 } 309 }
310 310
311 // Кабинет работника 311 // Кабинет работника
312 public function cabinet(Request $request) 312 public function cabinet(Request $request)
313 { 313 {
314 // дата год и месяц 314 // дата год и месяц
315 $get_date = date('Y.m'); 315 $get_date = date('Y.m');
316 316
317 $id = Auth()->user()->id; 317 $id = Auth()->user()->id;
318 318
319 $Infobloks = infobloks::query()->get(); 319 $Infobloks = infobloks::query()->get();
320 320
321 $Worker = Worker::query()->with('users')->with('sertificate')->with('prev_company')-> 321 $Worker = Worker::query()->with('users')->with('sertificate')->with('prev_company')->
322 with('infobloks')->with('place_worker')-> 322 with('infobloks')->with('place_worker')->
323 WhereHas('users', 323 WhereHas('users',
324 function (Builder $query) use ($id) {$query->Where('id', $id); 324 function (Builder $query) use ($id) {$query->Where('id', $id);
325 })->get(); 325 })->get();
326 326
327 $Job_titles = Job_title::query()->where('is_remove', '=', '0')-> 327 $Job_titles = Job_title::query()->where('is_remove', '=', '0')->
328 where('is_bd', '=' , '1')-> 328 where('is_bd', '=' , '1')->
329 OrderByDesc('sort')->OrderBy('name')->get(); 329 OrderByDesc('sort')->OrderBy('name')->get();
330 330
331 331
332 $stat = Static_worker::query()->where('year_month', '=', $get_date) 332 $stat = Static_worker::query()->where('year_month', '=', $get_date)
333 ->where('user_id', '=', $id) 333 ->where('user_id', '=', $id)
334 ->get(); 334 ->get();
335 335
336 336
337 // 10% 337 // 10%
338 338
339 $persent = 10; 339 $persent = 10;
340 $persent1 = 0; 340 $persent1 = 0;
341 $persent2 = 0; 341 $persent2 = 0;
342 $persent3 = 0; 342 $persent3 = 0;
343 $persent4 = 0; 343 $persent4 = 0;
344 $persent5 = 0; 344 $persent5 = 0;
345 345
346 if ((!empty($Worker[0]->telephone)) && 346 if ((!empty($Worker[0]->telephone)) &&
347 (!empty($Worker[0]->email)) && (!empty($Worker[0]->experience)) && 347 (!empty($Worker[0]->email)) && (!empty($Worker[0]->experience)) &&
348 (!empty($Worker[0]->city)) && (!empty($Worker[0]->old_year))) { 348 (!empty($Worker[0]->city)) && (!empty($Worker[0]->old_year))) {
349 // 40% 349 // 40%
350 $persent = $persent + 40; 350 $persent = $persent + 40;
351 $persent1 = 40; 351 $persent1 = 40;
352 } 352 }
353 353
354 //dd($Worker[0]->status_work, $Worker[0]->telephone, $Worker[0]->email, $Worker[0]->experience, $Worker[0]->city, $Worker[0]->old_year); 354 //dd($Worker[0]->status_work, $Worker[0]->telephone, $Worker[0]->email, $Worker[0]->experience, $Worker[0]->city, $Worker[0]->old_year);
355 355
356 if ($Worker[0]->sertificate->count() > 0) { 356 if ($Worker[0]->sertificate->count() > 0) {
357 // 15% 357 // 15%
358 $persent = $persent + 15; 358 $persent = $persent + 15;
359 $persent2 = 15; 359 $persent2 = 15;
360 } 360 }
361 361
362 if ($Worker[0]->infobloks->count() > 0) { 362 if ($Worker[0]->infobloks->count() > 0) {
363 // 20% 363 // 20%
364 $persent = $persent + 20; 364 $persent = $persent + 20;
365 $persent3 = 20; 365 $persent3 = 20;
366 } 366 }
367 367
368 if ($Worker[0]->prev_company->count() > 0) { 368 if ($Worker[0]->prev_company->count() > 0) {
369 // 10% 369 // 10%
370 $persent = $persent + 10; 370 $persent = $persent + 10;
371 $persent4 = 10; 371 $persent4 = 10;
372 } 372 }
373 373
374 if (!empty($Worker[0]->photo)) { 374 if (!empty($Worker[0]->photo)) {
375 // 5% 375 // 5%
376 $persent = $persent + 5; 376 $persent = $persent + 5;
377 $persent5 = 5; 377 $persent5 = 5;
378 } 378 }
379 379
380 $status_work = WorkerStatuses::getWorkerStatuses(); 380 $status_work = WorkerStatuses::getWorkerStatuses();
381 $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; 381 $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует'];
382 $info_blocks = infobloks::query()->OrderBy('name')->get(); 382 $info_blocks = infobloks::query()->OrderBy('name')->get();
383 383
384 $worker = Worker::query() 384 $worker = Worker::query()
385 ->with('users') 385 ->with('users')
386 ->with('sertificate') 386 ->with('sertificate')
387 ->with('prev_company') 387 ->with('prev_company')
388 ->with('infobloks') 388 ->with('infobloks')
389 ->with('place_worker') 389 ->with('place_worker')
390 ->with('job_titles') 390 ->with('job_titles')
391 ->WhereHas('users', function (Builder $query) use ($id) { 391 ->WhereHas('users', function (Builder $query) use ($id) {
392 $query->Where('id', $id); 392 $query->Where('id', $id);
393 }) 393 })
394 ->first(); 394 ->first();
395 if ($worker->dop_info->count()){ 395 if ($worker->dop_info->count()){
396 $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray(); 396 $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray();
397 } 397 }
398 398
399 //dd($worker->dop_info); 399 //dd($worker->dop_info);
400 400
401 if ($request->has('print')) { 401 if ($request->has('print')) {
402 dd($Worker); 402 dd($Worker);
403 } else { 403 } else {
404 return view('workers.cabinet', compact( 'persent', 'Job_titles', 'stat', 404 return view('workers.cabinet', compact( 'persent', 'Job_titles', 'stat',
405 'worker', 'info_blocks', 'status_work', 'additional_document_statuses' 405 'worker', 'info_blocks', 'status_work', 'additional_document_statuses'
406 )); 406 ));
407 } 407 }
408 } 408 }
409 409
410 // Сохранение данных 410 // Сохранение данных
411 public function cabinet_save(Worker $worker, Request $request) 411 public function cabinet_save(Worker $worker, Request $request)
412 { 412 {
413 $id = $worker->id; 413 $id = $worker->id;
414 $params = $request->all(); 414 $params = $request->all();
415 $job_title_id = $request->get('job_title_id'); 415 $job_title_id = $request->get('job_title_id');
416 416
417 $rules = [ 417 $rules = [
418 'surname' => ['required', 'string', 'max:255'], 418 'surname' => ['required', 'string', 'max:255'],
419 'name_man' => ['required', 'string', 'max:255'], 419 'name_man' => ['required', 'string', 'max:255'],
420 'email' => ['required', 'string', 'email', 'max:255'], 420 'email' => ['required', 'string', 'email', 'max:255'],
421 421
422 ]; 422 ];
423 423
424 $messages = [ 424 $messages = [
425 'required' => 'Укажите обязательное поле', 425 'required' => 'Укажите обязательное поле',
426 'min' => [ 426 'min' => [
427 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 427 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
428 'integer' => 'Поле «:attribute» должно быть :min или больше', 428 'integer' => 'Поле «:attribute» должно быть :min или больше',
429 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 429 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
430 ], 430 ],
431 'max' => [ 431 'max' => [
432 'string' => 'Поле «:attribute» должно быть не больше :max символов', 432 'string' => 'Поле «:attribute» должно быть не больше :max символов',
433 'integer' => 'Поле «:attribute» должно быть :max или меньше', 433 'integer' => 'Поле «:attribute» должно быть :max или меньше',
434 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 434 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
435 ] 435 ]
436 ]; 436 ];
437 437
438 $validator = Validator::make($params, $rules, $messages); 438 $validator = Validator::make($params, $rules, $messages);
439 439
440 if ($validator->fails()) { 440 if ($validator->fails()) {
441 return redirect()->route('worker.cabinet')->withErrors($validator); 441 return redirect()->route('worker.cabinet')->withErrors($validator);
442 } else { 442 } else {
443 443
444 if ($request->has('photo')) { 444 if ($request->has('photo')) {
445 if (!empty($worker->photo)) { 445 if (!empty($worker->photo)) {
446 Storage::delete($worker->photo); 446 Storage::delete($worker->photo);
447 } 447 }
448 $params['photo'] = $request->file('photo')->store("worker/$id", 'public'); 448 $params['photo'] = $request->file('photo')->store("worker/$id", 'public');
449 } 449 }
450 450
451 if ($request->has('file')) { 451 if ($request->has('file')) {
452 if (!empty($worker->file)) { 452 if (!empty($worker->file)) {
453 Storage::delete($worker->file); 453 Storage::delete($worker->file);
454 } 454 }
455 $params['file'] = $request->file('file')->store("worker/$id", 'public'); 455 $params['file'] = $request->file('file')->store("worker/$id", 'public');
456 } 456 }
457 457
458 $worker->update($params); 458 $worker->update($params);
459 $use = User::find($worker->user_id); 459 $use = User::find($worker->user_id);
460 $use->surname = $request->get('surname'); 460 $use->surname = $request->get('surname');
461 $use->name_man = $request->get('name_man'); 461 $use->name_man = $request->get('name_man');
462 $use->surname2 = $request->get('surname2'); 462 $use->surname2 = $request->get('surname2');
463 463
464 $use->save(); 464 $use->save();
465 $worker->job_titles()->sync($job_title_id); 465 $worker->job_titles()->sync($job_title_id);
466 466
467 return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены'); 467 return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены');
468 } 468 }
469 } 469 }
470 470
471 public function cabinet_save_foto(Worker $worker, Request $request){ 471 public function cabinet_save_foto(Worker $worker, Request $request){
472 $params = ['photo' => null]; 472 $params = ['photo' => null];
473 473
474 if ($request->has('photo')) { 474 if ($request->has('photo')) {
475 if (!empty($worker->photo)) { 475 if (!empty($worker->photo)) {
476 Storage::delete($worker->photo); 476 Storage::delete($worker->photo);
477 } 477 }
478 $params['photo'] = $request->file('photo')->store("worker/$worker->id", 'public'); 478 $params['photo'] = $request->file('photo')->store("worker/$worker->id", 'public');
479 } 479 }
480 480
481 if ($request->has('file')) { 481 if ($request->has('file')) {
482 if (!empty($worker->file)) { 482 if (!empty($worker->file)) {
483 Storage::delete($worker->file); 483 Storage::delete($worker->file);
484 } 484 }
485 $params['file'] = $request->file('file')->store("worker/$worker->id", 'public'); 485 $params['file'] = $request->file('file')->store("worker/$worker->id", 'public');
486 } 486 }
487 487
488 $worker->update($params); 488 $worker->update($params);
489 489
490 return redirect()->route('worker.cabinet'); 490 return redirect()->route('worker.cabinet');
491 } 491 }
492 492
493 // Сообщения данные 493 // Сообщения данные
494 public function messages($type_message) 494 public function messages($type_message)
495 { 495 {
496 $user_id = Auth()->user()->id; 496 $user_id = Auth()->user()->id;
497 497
498 $chats = Chat::get_user_chats($user_id); 498 $chats = Chat::get_user_chats($user_id);
499 $admin_chat = Chat::get_user_admin_chat($user_id); 499 $admin_chat = Chat::get_user_admin_chat($user_id);
500 $user_type = 'worker'; 500 $user_type = 'worker';
501 501
502 return view('workers.messages', compact('chats', 'admin_chat','user_id', 'user_type')); 502 return view('workers.messages', compact('chats', 'admin_chat','user_id', 'user_type'));
503 } 503 }
504 504
505 // Избранный 505 // Избранный
506 public function favorite() 506 public function favorite()
507 { 507 {
508 return view('workers.favorite'); 508 return view('workers.favorite');
509 } 509 }
510 510
511 // Сменить пароль 511 // Сменить пароль
512 public function new_password() 512 public function new_password()
513 { 513 {
514 $email = Auth()->user()->email; 514 $email = Auth()->user()->email;
515 return view('workers.new_password', compact('email')); 515 return view('workers.new_password', compact('email'));
516 } 516 }
517 517
518 // Обновление пароля 518 // Обновление пароля
519 public function save_new_password(Request $request) { 519 public function save_new_password(Request $request) {
520 $use = Auth()->user(); 520 $use = Auth()->user();
521 $request->validate([ 521 $request->validate([
522 'password' => 'required|string', 522 'password' => 'required|string',
523 'new_password' => 'required|string', 523 'new_password' => 'required|string',
524 'new_password2' => 'required|string' 524 'new_password2' => 'required|string'
525 ]); 525 ]);
526 526
527 if ($request->get('new_password') == $request->get('new_password2')) 527 if ($request->get('new_password') == $request->get('new_password2'))
528 if ($request->get('password') !== $request->get('new_password')) { 528 if ($request->get('password') !== $request->get('new_password')) {
529 $credentials = $request->only('email', 'password'); 529 $credentials = $request->only('email', 'password');
530 if (Auth::attempt($credentials, $request->has('save_me'))) { 530 if (Auth::attempt($credentials, $request->has('save_me'))) {
531 531
532 if (!is_null($use->email_verified_at)){ 532 if (!is_null($use->email_verified_at)){
533 533
534 $user_data = User_Model::find($use->id); 534 $user_data = User_Model::find($use->id);
535 $user_data->update([ 535 $user_data->update([
536 'password' => Hash::make($request->get('new_password')), 536 'password' => Hash::make($request->get('new_password')),
537 'pubpassword' => base64_encode($request->get('new_password')), 537 'pubpassword' => base64_encode($request->get('new_password')),
538 ]); 538 ]);
539 return redirect() 539 return redirect()
540 ->route('worker.new_password') 540 ->route('worker.new_password')
541 ->with('success', 'Поздравляю! Вы обновили свой пароль!'); 541 ->with('success', 'Поздравляю! Вы обновили свой пароль!');
542 } 542 }
543 543
544 return redirect() 544 return redirect()
545 ->route('worker.new_password') 545 ->route('worker.new_password')
546 ->withError('Данная учетная запись не было верифицированна!'); 546 ->withError('Данная учетная запись не было верифицированна!');
547 } 547 }
548 } 548 }
549 549
550 return redirect() 550 return redirect()
551 ->route('worker.new_password') 551 ->route('worker.new_password')
552 ->withErrors('Не совпадение данных, обновите пароли!'); 552 ->withErrors('Не совпадение данных, обновите пароли!');
553 } 553 }
554 554
555 // Удаление профиля форма 555 // Удаление профиля форма
556 public function delete_profile() 556 public function delete_profile()
557 { 557 {
558 $login = Auth()->user()->email; 558 $login = Auth()->user()->email;
559 return view('workers.delete_profile', compact('login')); 559 return view('workers.delete_profile', compact('login'));
560 } 560 }
561 561
562 // Удаление профиля код 562 // Удаление профиля код
563 public function delete_profile_result(Request $request) { 563 public function delete_profile_result(Request $request) {
564 $Answer = $request->all(); 564 $Answer = $request->all();
565 $user_id = Auth()->user()->id; 565 $user_id = Auth()->user()->id;
566 $request->validate([ 566 $request->validate([
567 'password' => 'required|string', 567 'password' => 'required|string',
568 ]); 568 ]);
569 569
570 $credentials = $request->only('email', 'password'); 570 $credentials = $request->only('email', 'password');
571 if (Auth::attempt($credentials)) { 571 if (Auth::attempt($credentials)) {
572 Auth::logout(); 572 Auth::logout();
573 $it = User_Model::find($user_id); 573 $it = User_Model::find($user_id);
574 $it->delete(); 574 $it->delete();
575 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); 575 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
576 } else { 576 } else {
577 return redirect()->route('worker.delete_profile') 577 return redirect()->route('worker.delete_profile')
578 ->withErrors( 'Неверный пароль! Нужен корректный пароль'); 578 ->withErrors( 'Неверный пароль! Нужен корректный пароль');
579 } 579 }
580 } 580 }
581 581
582 // Регистрация соискателя 582 // Регистрация соискателя
583 public function register_worker(Request $request) 583 public function register_worker(Request $request)
584 { 584 {
585 $params = $request->all(); 585 $params = $request->all();
586 $params['is_worker'] = 1; 586 $params['is_worker'] = 1;
587 587
588 $rules = [ 588 $rules = [
589 'surname' => ['required', 'string', 'max:255'], 589 'surname' => ['required', 'string', 'max:255'],
590 'name_man' => ['required', 'string', 'max:255'], 590 'name_man' => ['required', 'string', 'max:255'],
591 'email' => ['required', 'email', 'max:255', 'unique:users'], 591 'email' => ['required', 'email', 'max:255', 'unique:users'],
592 'password' => ['required', 'string', 'min:6'] 592 'password' => ['required', 'string', 'min:6']
593 ]; 593 ];
594 594
595 $messages = [ 595 $messages = [
596 'required' => 'Укажите обязательное поле', 596 'required' => 'Укажите обязательное поле',
597 'min' => [ 597 'min' => [
598 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 598 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
599 'integer' => 'Поле «:attribute» должно быть :min или больше', 599 'integer' => 'Поле «:attribute» должно быть :min или больше',
600 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 600 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
601 ], 601 ],
602 'max' => [ 602 'max' => [
603 'string' => 'Поле «:attribute» должно быть не больше :max символов', 603 'string' => 'Поле «:attribute» должно быть не больше :max символов',
604 'integer' => 'Поле «:attribute» должно быть :max или меньше', 604 'integer' => 'Поле «:attribute» должно быть :max или меньше',
605 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 605 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
606 ] 606 ]
607 ]; 607 ];
608 608
609 $email = $request->get('email'); 609 $email = $request->get('email');
610 if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) { 610 if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) {
611 return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл")); 611 return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл"));
612 } 612 }
613 613
614 if ($request->get('password') !== $request->get('confirmed')){ 614 if ($request->get('password') !== $request->get('confirmed')){
615 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); 615 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля"));
616 } 616 }
617 617
618 if (strlen($request->get('password')) < 6) { 618 if (strlen($request->get('password')) < 6) {
619 return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); 619 return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!"));
620 } 620 }
621 621
622 /*$haystack = $request->get('password'); 622 /*$haystack = $request->get('password');
623 623
624 $specsumbol = Array('!','~', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', ';', ':', '<', '>', '?'); 624 $specsumbol = Array('!','~', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', ';', ':', '<', '>', '?');
625 $alpha = Array('Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 625 $alpha = Array('Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z',
626 'X', 'C', 'V', 'B', 'N', 'M'); 626 'X', 'C', 'V', 'B', 'N', 'M');
627 $lenpwd_bool = true; 627 $lenpwd_bool = true;
628 $spec_bool = false; 628 $spec_bool = false;
629 $alpha_bool = false; 629 $alpha_bool = false;
630 630
631 if (strlen($haystack) < 8) $lenpwd_bool = false; 631 if (strlen($haystack) < 8) $lenpwd_bool = false;
632 632
633 foreach ($specsumbol as $it) { 633 foreach ($specsumbol as $it) {
634 if (strpos($haystack, $it) !== false) { 634 if (strpos($haystack, $it) !== false) {
635 $spec_bool = true; 635 $spec_bool = true;
636 } 636 }
637 } 637 }
638 638
639 foreach ($alpha as $it) { 639 foreach ($alpha as $it) {
640 if (strpos($haystack, $it) !== false) { 640 if (strpos($haystack, $it) !== false) {
641 $alpha_bool = true; 641 $alpha_bool = true;
642 } 642 }
643 } 643 }
644 644
645 if ((!$spec_bool) || (!$alpha_bool)) { 645 if ((!$spec_bool) || (!$alpha_bool)) {
646 return json_encode(Array("ERROR" => "Error: Нет спецсимволов в пароле, латинские буквы заглавные, а также один из символов: !~#$%^&*()-=;,:<>?")); 646 return json_encode(Array("ERROR" => "Error: Нет спецсимволов в пароле, латинские буквы заглавные, а также один из символов: !~#$%^&*()-=;,:<>?"));
647 }*/ 647 }*/
648 648
649 if (($request->has('politik')) && ($request->get('politik') == 1)) { 649 if (($request->has('politik')) && ($request->get('politik') == 1)) {
650 $validator = Validator::make($params, $rules, $messages); 650 $validator = Validator::make($params, $rules, $messages);
651 651
652 if ($validator->fails()) { 652 if ($validator->fails()) {
653 return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); 653 return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе."));
654 } else { 654 } else {
655 //dd($params); 655 //dd($params);
656 $user = $this->create($params); 656 $user = $this->create($params);
657 event(new Registered($user)); 657 event(new Registered($user));
658 Auth::guard()->login($user); 658 Auth::guard()->login($user);
659 } 659 }
660 if ($user) { 660 if ($user) {
661 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));; 661 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));;
662 } else { 662 } else {
663 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!")); 663 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!"));
664 } 664 }
665 665
666 } else { 666 } else {
667 return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!")); 667 return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!"));
668 } 668 }
669 } 669 }
670 670
671 // Звездная оценка и ответ 671 // Звездная оценка и ответ
672 public function stars_answer(Request $request) { 672 public function stars_answer(Request $request) {
673 $params = $request->all(); 673 $params = $request->all();
674 $rules = [ 674 $rules = [
675 'message' => ['required', 'string', 'max:255'], 675 'message' => ['required', 'string', 'max:255'],
676 ]; 676 ];
677 677
678 $messages = [ 678 $messages = [
679 'required' => 'Укажите обязательное поле', 679 'required' => 'Укажите обязательное поле',
680 'min' => [ 680 'min' => [
681 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 681 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
682 'integer' => 'Поле «:attribute» должно быть :min или больше', 682 'integer' => 'Поле «:attribute» должно быть :min или больше',
683 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 683 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
684 ], 684 ],
685 'max' => [ 685 'max' => [
686 'string' => 'Поле «:attribute» должно быть не больше :max символов', 686 'string' => 'Поле «:attribute» должно быть не больше :max символов',
687 'integer' => 'Поле «:attribute» должно быть :max или меньше', 687 'integer' => 'Поле «:attribute» должно быть :max или меньше',
688 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 688 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
689 ] 689 ]
690 ]; 690 ];
691 $response_worker = ResponseWork::create($params); 691 $response_worker = ResponseWork::create($params);
692 return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!'); 692 return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!');
693 } 693 }
694 694
695 public function TestWorker() 695 public function TestWorker()
696 { 696 {
697 $Use = new User(); 697 $Use = new User();
698 698
699 $Code_user = $Use->create([ 699 $Code_user = $Use->create([
700 'name' => 'surname name_man', 700 'name' => 'surname name_man',
701 'name_man' => 'name_man', 701 'name_man' => 'name_man',
702 'surname' => 'surname', 702 'surname' => 'surname',
703 'surname2' => 'surname2', 703 'surname2' => 'surname2',
704 'subscribe_email' => '1', 704 'subscribe_email' => '1',
705 'email' => 'email@mail.com', 705 'email' => 'email@mail.com',
706 'telephone' => '1234567890', 706 'telephone' => '1234567890',
707 'password' => Hash::make('password'), 707 'password' => Hash::make('password'),
708 'pubpassword' => base64_encode('password'), 708 'pubpassword' => base64_encode('password'),
709 'email_verified_at' => Carbon::now(), 709 'email_verified_at' => Carbon::now(),
710 'is_worker' => 1, 710 'is_worker' => 1,
711 ]); 711 ]);
712 712
713 if ($Code_user->id > 0) { 713 if ($Code_user->id > 0) {
714 $Worker = new Worker(); 714 $Worker = new Worker();
715 $Worker->user_id = $Code_user->id; 715 $Worker->user_id = $Code_user->id;
716 $Worker->position_work = 1; //'job_titles'; 716 $Worker->position_work = 1; //'job_titles';
717 $Worker->email = 'email@email.com'; 717 $Worker->email = 'email@email.com';
718 $Worker->telephone = '1234567890'; 718 $Worker->telephone = '1234567890';
719 $status = $Worker->save(); 719 $status = $Worker->save();
720 720
721 $Title_Worker = new Title_worker(); 721 $Title_Worker = new Title_worker();
722 $Title_Worker->worker_id = $Worker->id; 722 $Title_Worker->worker_id = $Worker->id;
723 $Title_Worker->job_title_id = 1; 723 $Title_Worker->job_title_id = 1;
724 $Title_Worker->save(); 724 $Title_Worker->save();
725 } 725 }
726 } 726 }
727 727
728 // Создание пользователя 728 // Создание пользователя
729 protected function create(array $data) 729 protected function create(array $data)
730 { 730 {
731 $Use = new User(); 731 $Use = new User();
732 732
733 $Code_user = $Use->create([ 733 $Code_user = $Use->create([
734 'name' => $data['surname']." ".$data['name_man'], 734 'name' => $data['surname']." ".$data['name_man'],
735 'name_man' => $data['name_man'], 735 'name_man' => $data['name_man'],
736 'surname' => $data['surname'], 736 'surname' => $data['surname'],
737 'surname2' => $data['surname2'], 737 'surname2' => $data['surname2'],
738 'subscribe_email' => $data['email'], 738 'subscribe_email' => $data['email'],
739 'email' => $data['email'], 739 'email' => $data['email'],
740 'telephone' => $data['telephone'], 740 'telephone' => $data['telephone'],
741 'password' => Hash::make($data['password']), 741 'password' => Hash::make($data['password']),
742 'pubpassword' => base64_encode($data['password']), 742 'pubpassword' => base64_encode($data['password']),
743 'email_verified_at' => Carbon::now(), 743 'email_verified_at' => Carbon::now(),
744 'is_worker' => $data['is_worker'], 744 'is_worker' => $data['is_worker'],
745 ]); 745 ]);
746 746
747 if ($Code_user->id > 0) { 747 if ($Code_user->id > 0) {
748 $Worker = new Worker(); 748 $Worker = new Worker();
749 $Worker->user_id = $Code_user->id; 749 $Worker->user_id = $Code_user->id;
750 $Worker->position_work = $data['job_titles']; 750 $Worker->position_work = $data['job_titles'];
751 $Worker->email = $data['email']; 751 $Worker->email = $data['email'];
752 $Worker->telephone = $data['telephone']; 752 $Worker->telephone = $data['telephone'];
753 $Worker->save(); 753 $Worker->save();
754 754
755 if (isset($Worker->id)) { 755 if (isset($Worker->id)) {
756 $Title_Worker = new Title_worker(); 756 $Title_Worker = new Title_worker();
757 $Title_Worker->worker_id = $Worker->id; 757 $Title_Worker->worker_id = $Worker->id;
758 $Title_Worker->job_title_id = $data['job_titles']; 758 $Title_Worker->job_title_id = $data['job_titles'];
759 $Title_Worker->save(); 759 $Title_Worker->save();
760 } 760 }
761 761
762 return $Code_user; 762 return $Code_user;
763 } 763 }
764 } 764 }
765 765
766 // Вакансии избранные 766 // Вакансии избранные
767 public function colorado(Request $request) { 767 public function colorado(Request $request) {
768 $IP_address = RusDate::ip_addr_client(); 768 $IP_address = RusDate::ip_addr_client();
769 $Arr = Like_vacancy::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get(); 769 $Arr = Like_vacancy::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get();
770 770
771 if ($Arr->count()) { 771 if ($Arr->count()) {
772 $A = Array(); 772 $A = Array();
773 foreach ($Arr as $it) { 773 foreach ($Arr as $it) {
774 $A[] = $it->code_record; 774 $A[] = $it->code_record;
775 } 775 }
776 776
777 $Query = Ad_employer::query()->whereIn('id', $A); 777 $Query = Ad_employer::query()->whereIn('id', $A);
778 } else { 778 } else {
779 $Query = Ad_employer::query()->where('id', '=', '0'); 779 $Query = Ad_employer::query()->where('id', '=', '0');
780 } 780 }
781 781
782 $Query = $Query->with('jobs')-> 782 $Query = $Query->with('jobs')->
783 with('cat')-> 783 with('cat')->
784 with('employer')-> 784 with('employer')->
785 whereHas('jobs_code', function ($query) use ($request) { 785 whereHas('jobs_code', function ($query) use ($request) {
786 if ($request->ajax()) { 786 if ($request->ajax()) {
787 if (null !== ($request->get('job'))) { 787 if (null !== ($request->get('job'))) {
788 $query->where('job_title_id', $request->get('job')); 788 $query->where('job_title_id', $request->get('job'));
789 } 789 }
790 } 790 }
791 })->select('ad_employers.*'); 791 })->select('ad_employers.*');
792 792
793 $Job_title = Job_title::query()->OrderBy('name')->get(); 793 $Job_title = Job_title::query()->OrderBy('name')->get();
794 794
795 $Query_count = $Query->count(); 795 $Query_count = $Query->count();
796 796
797 $Query = $Query->OrderBy('updated_at')->paginate(3); 797 $Query = $Query->OrderBy('updated_at')->paginate(3);
798 798
799 799
800 return view('workers.favorite', compact('Query', 800 return view('workers.favorite', compact('Query',
801 'Query_count', 801 'Query_count',
802 'Job_title')); 802 'Job_title'));
803 803
804 } 804 }
805 805
806 //Переписка 806 //Переписка
807 public function dialog(Chat $chat, Request $request) { 807 public function dialog(Chat $chat, Request $request) {
808 // Получение параметров. 808 // Получение параметров.
809 if ($request->has('ad_employer')){ 809 if ($request->has('ad_employer')){
810 $ad_employer = $request->get('ad_employer'); 810 $ad_employer = $request->get('ad_employer');
811 } else { 811 } else {
812 $ad_employer = 0; 812 $ad_employer = 0;
813 } 813 }
814 814
815 $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first(); 815 $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first();
816 $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first(); 816 $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first();
817 817
818 $Messages = Chat::get_chat_messages($chat); 818 $Messages = Chat::get_chat_messages($chat);
819 819
820 Message::where('user_id', '=', $chat->to_user_id) 820 Message::where('chat_id_to', '=', $chat->id)->update(['flag_new' => 0]);
821 ->where('to_user_id', '=', $chat->user_id)
822 ->update(['flag_new' => 0]);
823 821
824 return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer')); 822 return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer'));
825 } 823 }
826 824
827 // Даунылоады 825 // Даунылоады
828 public function download(Worker $worker) { 826 public function download(Worker $worker) {
829 $arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...']; 827 $arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...'];
830 view()->share('house',$arr_house); 828 view()->share('house',$arr_house);
831 $pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape'); 829 $pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape');
832 return $pdf->stream(); 830 return $pdf->stream();
833 } 831 }
834 832
835 // Поднятие анкеты 833 // Поднятие анкеты
836 public function up(Worker $worker) { 834 public function up(Worker $worker) {
837 $worker->updated_at = Carbon::now(); 835 $worker->updated_at = Carbon::now();
838 $worker->save(); 836 $worker->save();
839 // 0 837 // 0
840 return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных'); 838 return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных');
841 } 839 }
842 840
843 // Форма сертификате 841 // Форма сертификате
844 public function new_sertificate(Worker $worker) { 842 public function new_sertificate(Worker $worker) {
845 return view('workers.sertificate_add', compact('worker')); 843 return view('workers.sertificate_add', compact('worker'));
846 } 844 }
847 845
848 // Добавление сертификата 846 // Добавление сертификата
849 public function add_serificate(SertificationRequest $request) { 847 public function add_serificate(SertificationRequest $request) {
850 $request->validate([ 848 $request->validate([
851 'name' => 'required|string|max:255', 849 'name' => 'required|string|max:255',
852 'end_begin' => 'required|date|date_format:d.m.Y' 850 'end_begin' => 'required|date|date_format:d.m.Y'
853 ], 851 ],
854 [ 852 [
855 'name' => 'Навание сертификата обязательно для заполнения.', 853 'name' => 'Навание сертификата обязательно для заполнения.',
856 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг' 854 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг'
857 ]); 855 ]);
858 856
859 $params = $request->all(); 857 $params = $request->all();
860 858
861 $end_begin = DateTime::createFromFormat('d.m.Y', $params['end_begin']); 859 $end_begin = DateTime::createFromFormat('d.m.Y', $params['end_begin']);
862 $params['end_begin'] = $end_begin->format('Y-m-d'); 860 $params['end_begin'] = $end_begin->format('Y-m-d');
863 861
864 $Sertificate = new sertification(); 862 $Sertificate = new sertification();
865 $Sertificate->create($params); 863 $Sertificate->create($params);
866 864
867 return response()->json([ 865 return response()->json([
868 'success' => true 866 'success' => true
869 ]); 867 ]);
870 } 868 }
871 869
872 // Удалить сертификат 870 // Удалить сертификат
873 public function delete_sertificate(sertification $doc) { 871 public function delete_sertificate(sertification $doc) {
874 $doc->delete(); 872 $doc->delete();
875 873
876 return redirect()->route('worker.cabinet'); 874 return redirect()->route('worker.cabinet');
877 } 875 }
878 876
879 // Редактирование сертификата 877 // Редактирование сертификата
880 public function edit_sertificate(Worker $worker, sertification $doc) { 878 public function edit_sertificate(Worker $worker, sertification $doc) {
881 return view('workers.sertificate_edit', compact('doc', 'worker')); 879 return view('workers.sertificate_edit', compact('doc', 'worker'));
882 } 880 }
883 881
884 // Редактирование обновление сертификата 882 // Редактирование обновление сертификата
885 public function update_serificate(SertificationRequest $request, sertification $doc) { 883 public function update_serificate(SertificationRequest $request, sertification $doc) {
886 $request->validate([ 884 $request->validate([
887 'name' => 'required|string|max:255', 885 'name' => 'required|string|max:255',
888 'end_begin' => 'required|date|date_format:d.m.Y' 886 'end_begin' => 'required|date|date_format:d.m.Y'
889 ], 887 ],
890 [ 888 [
891 'name' => 'Навание сертификата обязательно для заполнения.', 889 'name' => 'Навание сертификата обязательно для заполнения.',
892 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг' 890 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг'
893 ]); 891 ]);
894 892
895 $all = $request->all(); 893 $all = $request->all();
896 894
897 $end_begin = DateTime::createFromFormat('d.m.Y', $all['end_begin']); 895 $end_begin = DateTime::createFromFormat('d.m.Y', $all['end_begin']);
898 $all['end_begin'] = $end_begin->format('Y-m-d'); 896 $all['end_begin'] = $end_begin->format('Y-m-d');
899 897
900 $doc->worker_id = $all['worker_id']; 898 $doc->worker_id = $all['worker_id'];
901 $doc->name = $all['name']; 899 $doc->name = $all['name'];
902 $doc->end_begin = $all['end_begin']; 900 $doc->end_begin = $all['end_begin'];
903 $doc->save(); 901 $doc->save();
904 902
905 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); 903 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!');
906 } 904 }
907 905
908 public function edit_diploms(Request $request, Worker $worker) { 906 public function edit_diploms(Request $request, Worker $worker) {
909 $dop_info_data = $request->input('diploms'); 907 $dop_info_data = $request->input('diploms');
910 908
911 if (empty($dop_info_data)) { 909 if (empty($dop_info_data)) {
912 return redirect()->route('worker.additional_documents')->with('error', 'Данные не предоставлены!'); 910 return redirect()->route('worker.additional_documents')->with('error', 'Данные не предоставлены!');
913 } 911 }
914 912
915 foreach ($dop_info_data as $infoblok_id => $status) { 913 foreach ($dop_info_data as $infoblok_id => $status) {
916 Dop_info::updateOrCreate( 914 Dop_info::updateOrCreate(
917 ['worker_id' => $worker->id, 'infoblok_id' => $infoblok_id], 915 ['worker_id' => $worker->id, 'infoblok_id' => $infoblok_id],
918 ['status' => $status] 916 ['status' => $status]
919 ); 917 );
920 } 918 }
921 919
922 return redirect()->route('worker.additional_documents')->with('success', 'Успешно сохранено!'); 920 return redirect()->route('worker.additional_documents')->with('success', 'Успешно сохранено!');
923 } 921 }
924 922
925 public function delete_add_diplom(Request $request, Worker $worker) { 923 public function delete_add_diplom(Request $request, Worker $worker) {
926 $infoblok_id = $request->get('infoblok_id'); 924 $infoblok_id = $request->get('infoblok_id');
927 925
928 if (Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->count() > 0) 926 if (Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->count() > 0)
929 $id = Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->delete(); 927 $id = Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->delete();
930 else { 928 else {
931 $params['infoblok_id'] = $infoblok_id; 929 $params['infoblok_id'] = $infoblok_id;
932 $params['worker_id'] = $worker->id; 930 $params['worker_id'] = $worker->id;
933 $params['status'] = $request->get('val'); 931 $params['status'] = $request->get('val');
934 $id = Dop_info::create($params); 932 $id = Dop_info::create($params);
935 //$id = $worker->infobloks()->sync([$infoblok_id]); 933 //$id = $worker->infobloks()->sync([$infoblok_id]);
936 } 934 }
937 935
938 //$Infoblocks = infobloks::query()->get(); 936 //$Infoblocks = infobloks::query()->get();
939 return $id; //redirect()->route('worker.cabinet')->getTargetUrl(); //view('workers.ajax.diploms_dop', compact('worker', 'Infoblocks')); 937 return $id; //redirect()->route('worker.cabinet')->getTargetUrl(); //view('workers.ajax.diploms_dop', compact('worker', 'Infoblocks'));
940 } 938 }
941 939
942 940
943 941
944 // Добавление диплома 942 // Добавление диплома
945 public function add_diplom_ajax(Request $request) { 943 public function add_diplom_ajax(Request $request) {
946 // конец 944 // конец
947 $params = $request->all(); 945 $params = $request->all();
948 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); 946 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count();
949 947
950 if ($count == 0) $dop_info = Dop_info::create($params); 948 if ($count == 0) $dop_info = Dop_info::create($params);
951 $Infoblocks = infobloks::query()->get(); 949 $Infoblocks = infobloks::query()->get();
952 $Worker = Worker::query()->where('id', $request->get('worker_id'))->get(); 950 $Worker = Worker::query()->where('id', $request->get('worker_id'))->get();
953 $data = Dop_info::query()->where('worker_id', $request->has('worker_id')); 951 $data = Dop_info::query()->where('worker_id', $request->has('worker_id'));
954 return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker')); 952 return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker'));
955 } 953 }
956 954
957 // Добавление диплома без ajax 955 // Добавление диплома без ajax
958 public function add_diplom(Worker $worker) { 956 public function add_diplom(Worker $worker) {
959 $worker_id = $worker->id; 957 $worker_id = $worker->id;
960 $Infoblocks = infobloks::query()->get(); 958 $Infoblocks = infobloks::query()->get();
961 return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks')); 959 return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks'));
962 } 960 }
963 // Сохранить 961 // Сохранить
964 // Сохраняю диплом 962 // Сохраняю диплом
965 public function add_diplom_save(Request $request) { 963 public function add_diplom_save(Request $request) {
966 $params = $request->all(); 964 $params = $request->all();
967 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); 965 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count();
968 if ($count == 0) $dop_info = Dop_info::create($params); 966 if ($count == 0) $dop_info = Dop_info::create($params);
969 return redirect()->route('worker.cabinet'); 967 return redirect()->route('worker.cabinet');
970 } 968 }
971 969
972 // Добавление стандартного документа 970 // Добавление стандартного документа
973 public function add_document(Worker $worker) { 971 public function add_document(Worker $worker) {
974 return view('workers.docs', compact('worker')); 972 return view('workers.docs', compact('worker'));
975 } 973 }
976 974
977 //Сохранение стандартого документа 975 //Сохранение стандартого документа
978 public function add_document_save(DocumentsRequest $request) { 976 public function add_document_save(DocumentsRequest $request) {
979 $params = $request->all(); 977 $params = $request->all();
980 place_works::create($params); 978 place_works::create($params);
981 return response()->json(['success' => true]); 979 return response()->json(['success' => true]);
982 } 980 }
983 981
984 // Редактирование документа 982 // Редактирование документа
985 public function edit_document(place_works $doc, Worker $worker) { 983 public function edit_document(place_works $doc, Worker $worker) {
986 return view('workers.docs-edit', compact('doc', 'worker')); 984 return view('workers.docs-edit', compact('doc', 'worker'));
987 } 985 }
988 986
989 //Сохранение отредактированного документа 987 //Сохранение отредактированного документа
990 public function edit_document_save(DocumentsRequest $request, place_works $doc) { 988 public function edit_document_save(DocumentsRequest $request, place_works $doc) {
991 $params = $request->all(); 989 $params = $request->all();
992 $doc->update($params); 990 $doc->update($params);
993 991
994 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); 992 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!');
995 } 993 }
996 994
997 // Удаление документа 995 // Удаление документа
998 public function delete_document(place_works $doc) { 996 public function delete_document(place_works $doc) {
999 $doc->delete(); 997 $doc->delete();
1000 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); 998 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!');
1001 } 999 }
1002 1000
1003 //Отправка нового сообщения 1001 //Отправка нового сообщения
1004 public function new_message(Request $request) { 1002 public function new_message(Request $request) {
1005 $params = $request->all(); 1003 $params = $request->all();
1006 1004
1007 $id = $params['send_user_id']; 1005 $id = $params['send_user_id'];
1008 $message_params = [ 1006 $message_params = [
1009 'title' => $params['send_title'], 1007 'title' => $params['send_title'],
1010 'text' => $params['send_text'], 1008 'text' => $params['send_text'],
1011 'ad_employer_id' => $params['send_vacancy'], 1009 'ad_employer_id' => $params['send_vacancy'],
1012 'flag_new' => 1 1010 'flag_new' => 1
1013 ]; 1011 ];
1014 1012
1015 $id_message = Message::add_message( 1013 $id_message = Message::add_message(
1016 $request, 1014 $request,
1017 $params['send_user_id'], 1015 $params['send_user_id'],
1018 $params['send_to_user_id'], 1016 $params['send_to_user_id'],
1019 $message_params, 1017 $message_params,
1020 file_store_path: "worker/$id" 1018 file_store_path: "worker/$id"
1021 ); 1019 );
1022 1020
1023 $data['message_id'] = $id_message; 1021 $data['message_id'] = $id_message;
1024 $data['ad_employer_id'] = $params['send_vacancy']; 1022 $data['ad_employer_id'] = $params['send_vacancy'];
1025 $data['job_title_id'] = $params['send_job_title_id']; 1023 $data['job_title_id'] = $params['send_job_title_id'];
1026 $data['flag'] = 1; 1024 $data['flag'] = 1;
1027 $ad_responce = ad_response::create($data); 1025 $ad_responce = ad_response::create($data);
1028 return redirect()->route('worker.messages', ['type_message' => 'output']); 1026 return redirect()->route('worker.messages', ['type_message' => 'output']);
1029 } 1027 }
1030 1028
1031 1029
1032 public function test123(Request $request) { 1030 public function test123(Request $request) {
1033 $params = $request->all(); 1031 $params = $request->all();
1034 $user1 = $params['user_id']; 1032 $user1 = $params['user_id'];
1035 $user2 = $params['to_user_id']; 1033 $user2 = $params['to_user_id'];
1036 $id_vacancy = $params['ad_employer_id']; 1034 $id_vacancy = $params['ad_employer_id'];
1037 $ad_name = $params['ad_name']; 1035 $ad_name = $params['ad_name'];
1038 1036
1039 $rules = [ 1037 $rules = [
1040 'text' => 'required|min:1|max:150000', 1038 'text' => 'required|min:1|max:150000',
1041 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' 1039 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000'
1042 ]; 1040 ];
1043 $messages = [ 1041 $messages = [
1044 'required' => 'Укажите обязательное поле', 1042 'required' => 'Укажите обязательное поле',
1045 'min' => [ 1043 'min' => [
1046 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 1044 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
1047 'integer' => 'Поле «:attribute» должно быть :min или больше', 1045 'integer' => 'Поле «:attribute» должно быть :min или больше',
1048 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 1046 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
1049 ], 1047 ],
1050 'max' => [ 1048 'max' => [
1051 'string' => 'Поле «:attribute» должно быть не больше :max символов', 1049 'string' => 'Поле «:attribute» должно быть не больше :max символов',
1052 'integer' => 'Поле «:attribute» должно быть :max или меньше', 1050 'integer' => 'Поле «:attribute» должно быть :max или меньше',
1053 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 1051 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
1054 ] 1052 ]
1055 ]; 1053 ];
1056 1054
1057 $validator = Validator::make($request->all(), $rules, $messages); 1055 $validator = Validator::make($request->all(), $rules, $messages);
1058 1056
1059 if ($validator->fails()) { 1057 if ($validator->fails()) {
1060 return redirect()->route('worker.dialog', ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]) 1058 return redirect()->route('worker.dialog', ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name])
1061 ->withErrors($validator); 1059 ->withErrors($validator);
1062 } else { 1060 } else {
1063 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); 1061 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
1064 1062
1065 return redirect()->route('worker.dialog', 1063 return redirect()->route('worker.dialog', ['chat' => $new_message->chat_id_from]);
1066 ['user1' => $user1, 'user2' => $user2, 'chat' => $new_message->chat_id_from]);
1067 1064
1068 } 1065 }
1069 } 1066 }
1070 1067
1071 // Информация о предыдущих компаниях 1068 // Информация о предыдущих компаниях
1072 public function new_prev_company(Worker $worker) { 1069 public function new_prev_company(Worker $worker) {
1073 return view('workers.prev_company_form', compact('worker')); 1070 return view('workers.prev_company_form', compact('worker'));
1074 } 1071 }
1075 1072
1076 // Добавление контакта компании 1073 // Добавление контакта компании
1077 public function add_prev_company(PrevCompanyRequest $request) { 1074 public function add_prev_company(PrevCompanyRequest $request) {
1078 // Возвращение параметров 1075 // Возвращение параметров
1079 $all = $request->all(); 1076 $all = $request->all();
1080 PrevCompany::create($all); 1077 PrevCompany::create($all);
1081 1078
1082 return response()->json(['success' => true]); 1079 return response()->json(['success' => true]);
1083 } 1080 }
1084 1081
1085 // Редактирование контакта компании 1082 // Редактирование контакта компании
1086 public function edit_prev_company(PrevCompany $doc, Worker $worker) { 1083 public function edit_prev_company(PrevCompany $doc, Worker $worker) {
1087 return view('workers.prev_company_edit_form', compact('doc', 'worker')); 1084 return view('workers.prev_company_edit_form', compact('doc', 'worker'));
1088 } 1085 }
1089 1086
1090 //Сохранение редактирования контакта компании 1087 //Сохранение редактирования контакта компании
1091 public function update_prev_company(PrevCompany $doc, Request $request){ 1088 public function update_prev_company(PrevCompany $doc, Request $request){
1092 $all = $request->all(); 1089 $all = $request->all();
1093 $doc->update($all); 1090 $doc->update($all);
1094 1091
1095 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись'); 1092 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись');
1096 } 1093 }
1097 1094
1098 // Удаление контакта предыдущей компании 1095 // Удаление контакта предыдущей компании
1099 public function delete_prev_company(PrevCompany $doc) { 1096 public function delete_prev_company(PrevCompany $doc) {
1100 $doc->delete(); 1097 $doc->delete();
1101 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); 1098 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!');
1102 } 1099 }
1103 } 1100 }
1104 1101
1105 1102
1 <?php 1 <?php
2 2
3 namespace App\Models; 3 namespace App\Models;
4 4
5 use Illuminate\Database\Eloquent\Factories\HasFactory; 5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Database\Eloquent\Model; 6 use Illuminate\Database\Eloquent\Model;
7 use Carbon\Carbon; 7 use Carbon\Carbon;
8 8
9 class Chat extends Model 9 class Chat extends Model
10 { 10 {
11 use HasFactory; 11 use HasFactory;
12 12
13 protected $fillable = [ 13 protected $fillable = [
14 'user_id', 14 'user_id',
15 'to_user_id', 15 'to_user_id',
16 'is_removed', 16 'is_removed',
17 'is_fixed', 17 'is_fixed',
18 'last_message_date', 18 'last_message_date',
19 'last_message_id', 19 'last_message_id',
20 'fixed_time', 20 'fixed_time',
21 'is_admin_chat' 21 'is_admin_chat'
22 ]; 22 ];
23 23
24 public function user() { 24 public function user() {
25 return $this->belongsTo(User::class, 'to_user_id'); 25 return $this->belongsTo(User::class, 'to_user_id');
26 } 26 }
27 27
28 public function worker() { 28 public function worker() {
29 return $this->belongsTo(Worker::class, 'to_user_id', 'user_id'); 29 return $this->belongsTo(Worker::class, 'to_user_id', 'user_id');
30 } 30 }
31 31
32 public function employer() { 32 public function employer() {
33 return $this->belongsTo(Employer::class, 'to_user_id', 'user_id'); 33 return $this->belongsTo(Employer::class, 'to_user_id', 'user_id');
34 } 34 }
35 35
36 public function last_message() { 36 public function last_message() {
37 return $this->belongsTo(Message::class, 'last_message_id'); 37 return $this->belongsTo(Message::class, 'last_message_id');
38 } 38 }
39 39
40 public function unread_messages() 40 public function unread_messages()
41 { 41 {
42 return $this->hasMany(Message::class, 'user_id', 'to_user_id'); 42 return $this->hasMany(Message::class, 'user_id', 'to_user_id');
43 } 43 }
44 44
45 public function admin_chat_unread_messages()
46 {
47 return $this->hasMany(Message::class, 'to_user_id', 'to_user_id');
48 }
49
45 public static function pin_chat(int $chat_id, $fixed) 50 public static function pin_chat(int $chat_id, $fixed)
46 { 51 {
47 return self::where('id', '=', $chat_id) 52 return self::where('id', '=', $chat_id)
48 ->update([ 53 ->update([
49 'is_fixed' => !empty($fixed) ? 1 : 0, 54 'is_fixed' => !empty($fixed) ? 1 : 0,
50 'fixation_date' => !empty($fixed) ? Carbon::now() : null 55 'fixation_date' => !empty($fixed) ? Carbon::now() : null
51 ]); 56 ]);
52 } 57 }
53 58
54 public static function remove_chat(int $chat_id) 59 public static function remove_chat(int $chat_id)
55 { 60 {
56 return self::where('id', '=', $chat_id) 61 return self::where('id', '=', $chat_id)
57 ->update(['is_removed' => 1]); 62 ->update(['is_removed' => 1]);
58 } 63 }
59 64
60 public static function get_user_chats(int $user_id){ 65 public static function get_user_chats(int $user_id){
61 return Chat::query() 66 return Chat::query()
62 ->with('user') 67 ->with('user')
63 ->with('worker') 68 ->with('worker')
64 ->with('employer') 69 ->with('employer')
65 ->with('last_message') 70 ->with('last_message')
66 ->withCount(['unread_messages' => function ($query) use($user_id) { 71 ->withCount(['unread_messages' => function ($query) use($user_id) {
67 $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1); 72 $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1);
68 }]) 73 }])
69 ->where('user_id', '=', $user_id) 74 ->where('user_id', '=', $user_id)
70 ->where('is_removed', '=', 0) 75 ->where('is_removed', '=', 0)
71 ->orderByDesc('is_fixed') 76 ->orderByDesc('is_fixed')
72 ->orderByDesc('fixation_date') 77 ->orderByDesc('fixation_date')
73 ->orderByDesc('last_message_date') 78 ->orderByDesc('last_message_date')
74 ->paginate(5) 79 ->paginate(5)
75 ; 80 ;
76 } 81 }
77 82
78 public static function get_user_admin_chat(int $user_id) 83 public static function get_user_admin_chat(int $user_id)
79 { 84 {
80 return Chat::query() 85 return Chat::query()
81 ->with('last_message') 86 ->with('last_message')
82 ->withCount(['unread_messages' => function ($query) use($user_id) { 87 ->withCount(['admin_chat_unread_messages' => function ($query) use($user_id) {
83 $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1); 88 $query->whereNull('chat_id_from')->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1);
84 }]) 89 }])
85 ->where('to_user_id', '=', $user_id) 90 ->where('to_user_id', '=', $user_id)
86 ->where('is_admin_chat', 1) 91 ->where('is_admin_chat', 1)
87 ->first() 92 ->first()
88 ; 93 ;
89 } 94 }
90 95
91 public static function get_chat_messages(Chat $chat){ 96 public static function get_chat_messages(Chat $chat){
92 if ($chat->is_admin_chat){ 97 if ($chat->is_admin_chat){
93 return Message::query() 98 return Message::query()
94 ->where('chat_id_to', $chat->id) 99 ->where('chat_id_to', $chat->id)
95 ->where('to_user_id', $chat->to_user_id) 100 ->where('to_user_id', $chat->to_user_id)
96 ->orderBy('created_at') 101 ->orderBy('created_at')
97 ->get() 102 ->get()
98 ; 103 ;
99 } else { 104 } else {
100 return Message::query() 105 return Message::query()
101 ->where(function ($query) use ($chat) { 106 ->where(function ($query) use ($chat) {
102 $query->where('chat_id_from', $chat->id)->orWhere('chat_id_to', $chat->id); 107 $query->where('chat_id_from', $chat->id)->orWhere('chat_id_to', $chat->id);
103 }) 108 })
104 ->where(function($query) use ($chat) { 109 ->where(function($query) use ($chat) {
105 $query 110 $query
106 ->where(function($query) use ($chat) { 111 ->where(function($query) use ($chat) {
107 $query->where('user_id', $chat->user_id)->where('to_user_id', $chat->to_user_id); 112 $query->where('user_id', $chat->user_id)->where('to_user_id', $chat->to_user_id);
108 }) 113 })
109 ->orWhere(function($query) use ($chat) { 114 ->orWhere(function($query) use ($chat) {
110 $query->where('user_id', $chat->to_user_id)->where('to_user_id', $chat->user_id); 115 $query->where('user_id', $chat->to_user_id)->where('to_user_id', $chat->user_id);
111 }) 116 })
112 ; 117 ;
113 }) 118 })
114 ->OrderBy('created_at') 119 ->OrderBy('created_at')
115 ->get() 120 ->get()
116 ; 121 ;
117 } 122 }
118 } 123 }
119 124
120 } 125 }
121 126
app/Models/MessagesRequests.php
1 <?php 1 <?php
2 2
3 namespace App\Models; 3 namespace App\Models;
4 4
5 use Illuminate\Database\Eloquent\Factories\HasFactory; 5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Database\Eloquent\Model; 6 use Illuminate\Database\Eloquent\Model;
7 7
8 class MessagesRequests extends Model 8 class MessagesRequests extends Model
9 { 9 {
10 use HasFactory; 10 use HasFactory;
11 11
12 protected $fillable = [ 12 protected $fillable = [
13 'user_id', 13 'user_id',
14 'job_titles', 14 'job_titles',
15 'text', 15 'text',
16 'is_rejected', 16 'is_rejected',
17 'is_sent' 17 'is_sent'
18 ]; 18 ];
19 19
20 public function getJobsAttribute() 20 public function getJobsAttribute()
21 { 21 {
22 $job_titles_ids = json_decode($this->attributes['job_titles'], true); 22 $job_titles_ids = json_decode($this->attributes['job_titles'], true);
23 return Job_title::whereIn('id', $job_titles_ids)->get(); 23 return Job_title::whereIn('id', $job_titles_ids)->get();
24 } 24 }
25 25
26 public function user() { 26 public function user() {
27 return $this->belongsTo(User::class, 'user_id'); 27 return $this->belongsTo(User::class, 'user_id');
28 } 28 }
29 29
30 public static function send_message($message_request_id) 30 public static function send_message($message_request_id)
31 { 31 {
32 $message_request = MessagesRequests::find($message_request_id); 32 $message_request = MessagesRequests::find($message_request_id);
33 $job_ids = json_decode($message_request->job_titles); 33 $job_ids = json_decode($message_request->job_titles);
34 34
35 if (!empty($job_ids)){ 35 if (!empty($job_ids)){
36 $workers = Title_worker::select('worker_id') 36 $title_workers = Title_worker::select('worker_id')
37 ->with('worker')
37 ->whereIN('job_title_id', $job_ids) 38 ->whereIN('job_title_id', $job_ids)
38 ->groupBy('worker_id') 39 ->groupBy('worker_id')
39 ->get() 40 ->get()
40 ; 41 ;
41 42
42 if ($workers->count()){ 43
44
45 if ($title_workers->count()){
43 $message_params = [ 46 $message_params = [
44 'text' => $message_request->text 47 'text' => $message_request->text
45 ]; 48 ];
46 foreach ($workers as $worker){ 49 foreach ($title_workers as $title_worker){
47 Message::add_message(null, $message_request->user_id, $worker->worker_id, $message_params, file_store_path : '/', is_admin_chat: true); 50 Message::add_message(null, $message_request->user_id, $title_worker->worker->user_id, $message_params, file_store_path : '/', is_admin_chat: true);
48 } 51 }
49 } 52 }
50 } 53 }
51 54
52 $message_request->update(['is_sent' => now()]); 55 $message_request->update(['is_sent' => now()]);
53 56
54 return true; 57 return true;
55 } 58 }
56 } 59 }
57 60
app/Models/Title_worker.php
1 <?php 1 <?php
2 2
3 namespace App\Models; 3 namespace App\Models;
4 4
5 use Illuminate\Database\Eloquent\Factories\HasFactory; 5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Database\Eloquent\Model; 6 use Illuminate\Database\Eloquent\Model;
7 7
8 class Title_worker extends Model 8 class Title_worker extends Model
9 { 9 {
10 use HasFactory; 10 use HasFactory;
11
12 public function worker() {
13 return $this->belongsTo(Worker::class, 'worker_id');
14 }
11 } 15 }
12 16
resources/views/chats/chats_list.blade.php
1 @if ($chats->count()) 1 @if ($chats->count())
2 @csrf 2 @csrf
3 3
4 @if($admin_chat) 4 @if($admin_chat)
5 <div class="messages__item hover-shadow admin-chat-wrap"> 5 <div class="messages__item hover-shadow admin-chat-wrap">
6 <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['chat' => $admin_chat->id]) }}"> 6 <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['chat' => $admin_chat->id]) }}">
7 @include('svg.logo_icon') 7 @include('svg.logo_icon')
8 <div class="messages__item-text"> 8 <div class="messages__item-text">
9 <div> 9 <div>
10 <b>Администратор сайта</b> 10 <b>Администратор сайта</b>
11 </div> 11 </div>
12 <div> 12 <div>
13 {{ $admin_chat->last_message->text }} 13 {{ $admin_chat->last_message->text }}
14 </div> 14 </div>
15 </div> 15 </div>
16 </a> 16 </a>
17 17
18 <div class="messages__item-actions" data-chat-id="{{ $admin_chat->id }}"> 18 <div class="messages__item-actions" data-chat-id="{{ $admin_chat->id }}">
19 <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($admin_chat->created_at)) }}</div> 19 <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($admin_chat->created_at)) }}</div>
20 <div class="messages__item-buttons">
21 @if($admin_chat->admin_chat_unread_messages_count > 0)
22 <div class="unread-messages-count mr-15">{{ $admin_chat->admin_chat_unread_messages_count }}</div>
23 @endif
24 </div>
20 </div> 25 </div>
21 </div> 26 </div>
22 @endif 27 @endif
23 28
24 @foreach($chats as $chat) 29 @foreach($chats as $chat)
25 <div class="messages__item hover-shadow {{ intval($chat->is_fixed) == 1 ? 'chat-fixed' : '' }}"> 30 <div class="messages__item hover-shadow {{ intval($chat->is_fixed) == 1 ? 'chat-fixed' : '' }}">
26 <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['chat' => $chat->id]) }}"> 31 <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['chat' => $chat->id]) }}">
27 <div class="messages__item-photo"> 32 <div class="messages__item-photo">
28 @if (isset($chat->employer->logo)) 33 @if (isset($chat->employer->logo))
29 <img src="{{ asset(Storage::url($chat->employer->logo)) }}" alt=""> 34 <img src="{{ asset(Storage::url($chat->employer->logo)) }}" alt="">
30 @elseif(isset($chat->worker->photo)) 35 @elseif(isset($chat->worker->photo))
31 <img src="{{ asset(Storage::url($chat->worker->photo)) }}" alt=""> 36 <img src="{{ asset(Storage::url($chat->worker->photo)) }}" alt="">
32 @else 37 @else
33 <img src="{{ asset('images/default_man.jpg') }}" alt=""> 38 <img src="{{ asset('images/default_man.jpg') }}" alt="">
34 @endif 39 @endif
35 </div> 40 </div>
36 <div class="messages__item-text"> 41 <div class="messages__item-text">
37 <div> 42 <div>
38 <b> 43 <b>
39 @if ($chat->employer && $chat->employer->name_company) 44 @if ($chat->employer && $chat->employer->name_company)
40 {{ $chat->employer->name_company }} 45 {{ $chat->employer->name_company }}
41 @else 46 @else
42 {{ $chat->user->surname . ' ' . $chat->user->name_man . ' ' . $chat->user->surname2 }} 47 {{ $chat->user->surname . ' ' . $chat->user->name_man . ' ' . $chat->user->surname2 }}
43 @endif 48 @endif
44 </b> 49 </b>
45 </div> 50 </div>
46 <div> 51 <div>
47 {{ $chat->last_message->text }} 52 {{ $chat->last_message->text }}
48 </div> 53 </div>
49 </div> 54 </div>
50 </a> 55 </a>
51 56
52 <div class="messages__item-actions" data-chat-id="{{ $chat->id }}"> 57 <div class="messages__item-actions" data-chat-id="{{ $chat->id }}">
53 <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($chat->created_at)) }}</div> 58 <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($chat->created_at)) }}</div>
54 <div class="messages__item-buttons"> 59 <div class="messages__item-buttons">
55 @if($chat->unread_messages_count > 0) 60 @if($chat->unread_messages_count > 0)
56 <div class="unread-messages-count mr-15">{{ $chat->unread_messages_count }}</div> 61 <div class="unread-messages-count mr-15">{{ $chat->unread_messages_count }}</div>
57 @endif 62 @endif
58 63
59 <button class="pin-chat {{ intval($chat->is_fixed) == 1 ? 'pin-on' : 'pin-off' }} mr-15"> 64 <button class="pin-chat {{ intval($chat->is_fixed) == 1 ? 'pin-on' : 'pin-off' }} mr-15">
60 @include('svg.pin_off') 65 @include('svg.pin_off')
61 </button> 66 </button>
62 <button class="remove-chat" data-fancybox data-src="#remove_chat"> 67 <button class="remove-chat" data-fancybox data-src="#remove_chat">
63 <svg> 68 <svg>
64 <use xlink:href="{{ asset('images/sprite.svg#del') }}"></use> 69 <use xlink:href="{{ asset('images/sprite.svg#del') }}"></use>
65 </svg> 70 </svg>
66 </button> 71 </button>
67 </div> 72 </div>
68 <div class="clear"></div> 73 <div class="clear"></div>
69 </div> 74 </div>
70 </div> 75 </div>
71 @endforeach 76 @endforeach
72 <div style="margin-top: 20px"> 77 <div style="margin-top: 20px">
73 {{ $chats->onEachSide(0)->appends($_GET)->links('paginate') }} 78 {{ $chats->onEachSide(0)->appends($_GET)->links('paginate') }}
74 </div><!-- конец --> 79 </div><!-- конец -->
75 @else 80 @else
76 <div class="notify"> 81 <div class="notify">
77 <svg> 82 <svg>
78 <use xlink:href="{{ asset('images/sprite.svg#i') }}"></use> 83 <use xlink:href="{{ asset('images/sprite.svg#i') }}"></use>
79 </svg> 84 </svg>
80 <span>Сообщений не найдено</span> 85 <span>Сообщений не найдено</span>
81 </div> 86 </div>
82 @endif 87 @endif
83 88
84 <script> 89 <script>
85 $(function (){ 90 $(function (){
86 $('.pin-chat').click(function(){ 91 $('.pin-chat').click(function(){
87 var this_btn = $(this); 92 var this_btn = $(this);
88 var chat_id = this_btn.closest('.messages__item-actions').data('chat-id'); 93 var chat_id = this_btn.closest('.messages__item-actions').data('chat-id');
89 var $is_fixed = this_btn.hasClass('pin-on') ? 0 : 1; 94 var $is_fixed = this_btn.hasClass('pin-on') ? 0 : 1;
90 95
91 $.ajax({ 96 $.ajax({
92 type: "POST", 97 type: "POST",
93 url: "{{ route('employer.pin_chat') }}", 98 url: "{{ route('employer.pin_chat') }}",
94 data: { 99 data: {
95 id: chat_id, 100 id: chat_id,
96 is_fixed: $is_fixed 101 is_fixed: $is_fixed
97 }, 102 },
98 headers: { 103 headers: {
99 'X-CSRF-TOKEN': $('[name="_token"]').val() 104 'X-CSRF-TOKEN': $('[name="_token"]').val()
100 }, 105 },
101 success: function(){ 106 success: function(){
102 location.reload(); 107 location.reload();
103 } 108 }
104 }); 109 });
105 }); 110 });
106 111
107 $('.remove-chat').click(function(){ 112 $('.remove-chat').click(function(){
108 var this_btn = $(this); 113 var this_btn = $(this);
109 var chat_id = this_btn.closest('.messages__item-actions').data('chat-id'); 114 var chat_id = this_btn.closest('.messages__item-actions').data('chat-id');
110 var wrap = this_btn.closest('.messages__item'); 115 var wrap = this_btn.closest('.messages__item');
111 var target = wrap.find('.messages__item-target').text(); 116 var target = wrap.find('.messages__item-target').text();
112 117
113 $('#remove_chat').data('chat-id', chat_id); 118 $('#remove_chat').data('chat-id', chat_id);
114 $('#remove_chat').find('.target-chat').text(target.trim()); 119 $('#remove_chat').find('.target-chat').text(target.trim());
115 }); 120 });
116 }); 121 });
117 </script> 122 </script>
118 123