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