Commit 9f5b1d0112e53e85197df30673ccf1f2f4923df1

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

Работа по проекту - финал

Showing 1 changed file with 0 additions and 2 deletions Inline Diff

app/Http/Controllers/MainController.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\Mail\MailRegistration; 7 use App\Mail\MailRegistration;
8 use App\Mail\MailRepair; 8 use App\Mail\MailRepair;
9 use App\Models\Ad_employer; 9 use App\Models\Ad_employer;
10 use App\Models\Ad_jobs; 10 use App\Models\Ad_jobs;
11 use App\Models\Category; 11 use App\Models\Category;
12 use App\Models\Education; 12 use App\Models\Education;
13 use App\Models\Employer; 13 use App\Models\Employer;
14 use App\Models\employers_main; 14 use App\Models\employers_main;
15 use App\Models\Job_title; 15 use App\Models\Job_title;
16 use App\Models\Like_vacancy; 16 use App\Models\Like_vacancy;
17 use App\Models\Like_worker; 17 use App\Models\Like_worker;
18 use App\Models\News; 18 use App\Models\News;
19 use App\Models\Positions; 19 use App\Models\Positions;
20 use App\Models\reclame; 20 use App\Models\reclame;
21 use App\Models\User; 21 use App\Models\User;
22 use Illuminate\Http\Request; 22 use Illuminate\Http\Request;
23 use Illuminate\Support\Facades\Auth; 23 use Illuminate\Support\Facades\Auth;
24 use Illuminate\Support\Facades\DB; 24 use Illuminate\Support\Facades\DB;
25 use Illuminate\Support\Facades\Hash; 25 use Illuminate\Support\Facades\Hash;
26 use Illuminate\Support\Facades\Mail; 26 use Illuminate\Support\Facades\Mail;
27 use Illuminate\Support\Facades\Validator; 27 use Illuminate\Support\Facades\Validator;
28 use App\Classes\StatusUser; 28 use App\Classes\StatusUser;
29 29
30 class MainController extends Controller 30 class MainController extends Controller
31 { 31 {
32 // Главная страница публичной части 32 // Главная страница публичной части
33 public function index() { 33 public function index() {
34 $news = News::query()->orderBy('id')->limit(6)->get(); 34 $news = News::query()->orderBy('id')->limit(6)->get();
35 35
36 $categories = Category::query()->selectRaw('count(ad_employers.id) as cnt, categories.*') 36 $categories = Category::query()->selectRaw('count(ad_employers.id) as cnt, categories.*')
37 ->join('ad_employers', 'ad_employers.category_id', '=', 'categories.id') 37 ->join('ad_employers', 'ad_employers.category_id', '=', 'categories.id')
38 ->OrderByDesc('created_at') 38 ->OrderByDesc('created_at')
39 ->GroupBy('categories.id') 39 ->GroupBy('categories.id')
40 ->get(); 40 ->get();
41 41
42 $Position = Positions::query()->get(); 42 $Position = Positions::query()->get();
43 43
44 /*$BigFlot = Array(); 44 /*$BigFlot = Array();
45 foreach ($Position as $position) { 45 foreach ($Position as $position) {
46 $BigFlot[] = DB::table('ad_jobs')->selectRaw('name, job_titles.id as id_title, count(`ad_jobs`.`id`) as cnt, ad_jobs.position_ship')-> 46 $BigFlot[] = DB::table('ad_jobs')->selectRaw('name, job_titles.id as id_title, count(`ad_jobs`.`id`) as cnt, ad_jobs.position_ship')->
47 orderBy('job_titles.sort')-> 47 orderBy('job_titles.sort')->
48 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')-> 48 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')->
49 where('position_ship', "$position->name")-> 49 where('position_ship', "$position->name")->
50 groupby('job_title_id','position_ship')-> 50 groupby('job_title_id','position_ship')->
51 get(); 51 get();
52 } 52 }
53 53
54 $BigFlot = Array(); 54 $BigFlot = Array();
55 55
56 foreach ($Position as $position) { 56 foreach ($Position as $position) {
57 57
58 $BigFlot[] = Ad_jobs::query()->with(['job_title' => function($query) { 58 $BigFlot[] = Ad_jobs::query()->with(['job_title' => function($query) {
59 $query->OrderBy('sort'); 59 $query->OrderBy('sort');
60 }])->whereHas('job_title', function ($query) use ($position) { 60 }])->whereHas('job_title', function ($query) use ($position) {
61 $query->where('position_id', $position->id); 61 $query->where('position_id', $position->id);
62 })-> 62 })->
63 distinct('job_title_id')-> 63 distinct('job_title_id')->
64 get(); 64 get();
65 }*/ 65 }*/
66 66
67 $BigFlot = Array(); 67 $BigFlot = Array();
68 foreach ($Position as $position) { 68 foreach ($Position as $position) {
69 $BigFlot[] = DB::table('ad_jobs')-> 69 $BigFlot[] = DB::table('ad_jobs')->
70 selectRaw('name, count(`ad_jobs`.`id`) as cnt, job_title_id, job_titles.name')-> 70 selectRaw('name, count(`ad_jobs`.`id`) as cnt, job_title_id, job_titles.name')->
71 orderByDesc('job_titles.sort')-> 71 orderByDesc('job_titles.sort')->
72 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')-> 72 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')->
73 where('job_titles.position_id', $position->id)-> 73 where('job_titles.position_id', $position->id)->
74 groupby('job_title_id')-> 74 groupby('job_title_id')->
75 get(); 75 get();
76 } 76 }
77 dd($BigFlot);
78
79 77
80 $employers = employers_main::query()->with('employer')->orderBy('id')->limit(8)->get(); 78 $employers = employers_main::query()->with('employer')->orderBy('id')->limit(8)->get();
81 $vacancy = Ad_jobs::query()->with('job_title')->orderBy('position_ship')->get(); 79 $vacancy = Ad_jobs::query()->with('job_title')->orderBy('position_ship')->get();
82 return view('index', compact('news', 'categories', 'employers', 'vacancy', 'BigFlot', 'Position')); 80 return view('index', compact('news', 'categories', 'employers', 'vacancy', 'BigFlot', 'Position'));
83 } 81 }
84 82
85 public function search_vacancies(Request $request) { 83 public function search_vacancies(Request $request) {
86 if ($request->has('search')) { 84 if ($request->has('search')) {
87 $search = $request->get('search'); 85 $search = $request->get('search');
88 $job_titles = Job_title::query()->where('name', 'LIKE', "%$search%")->first(); 86 $job_titles = Job_title::query()->where('name', 'LIKE', "%$search%")->first();
89 if (isset($job_titles->id)) 87 if (isset($job_titles->id))
90 if ($job_titles->id > 0) 88 if ($job_titles->id > 0)
91 return redirect()->route('vacancies', ['job' => $job_titles->id]); 89 return redirect()->route('vacancies', ['job' => $job_titles->id]);
92 } 90 }
93 } 91 }
94 92
95 // Лайк вакансии 93 // Лайк вакансии
96 public function like_vacancy(Request $request) { 94 public function like_vacancy(Request $request) {
97 $IP_address = RusDate::ip_addr_client(); 95 $IP_address = RusDate::ip_addr_client();
98 96
99 if ($request->has('code_record')) { 97 if ($request->has('code_record')) {
100 if ($request->has('delete')) { 98 if ($request->has('delete')) {
101 $atomic_era = Like_vacancy::select('id')-> 99 $atomic_era = Like_vacancy::select('id')->
102 where('code_record', '=', $request-> 100 where('code_record', '=', $request->
103 get('code_record'))->first(); 101 get('code_record'))->first();
104 102
105 DB::table('like_vacancy')->where('code_record', $request->get('code_record'))->delete(); 103 DB::table('like_vacancy')->where('code_record', $request->get('code_record'))->delete();
106 104
107 } else { 105 } else {
108 $params = $request->all(); 106 $params = $request->all();
109 $params['ip_address'] = $IP_address; 107 $params['ip_address'] = $IP_address;
110 Like_vacancy::create($params); 108 Like_vacancy::create($params);
111 } 109 }
112 } 110 }
113 } 111 }
114 112
115 // Лайк соискателю. 113 // Лайк соискателю.
116 public function like_worker(Request $request) { 114 public function like_worker(Request $request) {
117 $IP_address = RusDate::ip_addr_client(); 115 $IP_address = RusDate::ip_addr_client();
118 116
119 if ($request->has('code_record')) { 117 if ($request->has('code_record')) {
120 if ($request->has('delete')) { 118 if ($request->has('delete')) {
121 $atomic_era = Like_worker::select('id')-> 119 $atomic_era = Like_worker::select('id')->
122 where('code_record', '=', $request-> 120 where('code_record', '=', $request->
123 get('code_record'))->first(); 121 get('code_record'))->first();
124 122
125 DB::table('like_worker')->where('code_record', $request->get('code_record'))->delete(); 123 DB::table('like_worker')->where('code_record', $request->get('code_record'))->delete();
126 124
127 return "Вот и результат удаления!"; 125 return "Вот и результат удаления!";
128 126
129 } else { 127 } else {
130 $params = $request->all(); 128 $params = $request->all();
131 $params['ip_address'] = $IP_address; 129 $params['ip_address'] = $IP_address;
132 Like_worker::create($params); 130 Like_worker::create($params);
133 } 131 }
134 } 132 }
135 } 133 }
136 134
137 135
138 public function vacancies(Request $request) { 136 public function vacancies(Request $request) {
139 //должности 137 //должности
140 $Job_title = Job_title::query()->orderBy('name')->get(); 138 $Job_title = Job_title::query()->orderBy('name')->get();
141 139
142 $categories = Category::query()->selectRaw('count(ad_employers.id) as cnt, categories.*') 140 $categories = Category::query()->selectRaw('count(ad_employers.id) as cnt, categories.*')
143 ->selectRaw('min(ad_employers.salary) as min_salary, max(ad_employers.salary) as max_salary') 141 ->selectRaw('min(ad_employers.salary) as min_salary, max(ad_employers.salary) as max_salary')
144 ->join('ad_employers', 'ad_employers.category_id', '=', 'categories.id') 142 ->join('ad_employers', 'ad_employers.category_id', '=', 'categories.id')
145 ->join('ad_jobs', 'ad_jobs.ad_employer_id', '=', 'ad_employers.id'); 143 ->join('ad_jobs', 'ad_jobs.ad_employer_id', '=', 'ad_employers.id');
146 144
147 //категории и вакансии 145 //категории и вакансии
148 if (($request->has('job')) && ($request->get('job') > 0)) { 146 if (($request->has('job')) && ($request->get('job') > 0)) {
149 $categories = $categories->Where('job_title_id', '=', $request->get('job')); 147 $categories = $categories->Where('job_title_id', '=', $request->get('job'));
150 } 148 }
151 149
152 $categories = $categories->OrderByDesc('created_at')->GroupBy('categories.id')->get(); 150 $categories = $categories->OrderByDesc('created_at')->GroupBy('categories.id')->get();
153 151
154 $Position = Positions::query()->get(); 152 $Position = Positions::query()->get();
155 153
156 /*$BigFlot = Array(); 154 /*$BigFlot = Array();
157 foreach ($Position as $position) { 155 foreach ($Position as $position) {
158 $War_flot = DB::table('ad_jobs')->selectRaw('name, job_titles.id as id_title, count(`ad_jobs`.`id`) as cnt, ad_jobs.position_ship')-> 156 $War_flot = DB::table('ad_jobs')->selectRaw('name, job_titles.id as id_title, count(`ad_jobs`.`id`) as cnt, ad_jobs.position_ship')->
159 orderBy('job_titles.sort')-> 157 orderBy('job_titles.sort')->
160 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')-> 158 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')->
161 where('position_ship', "$position->name"); 159 where('position_ship', "$position->name");
162 if (($request->has('job')) && ($request->get('job') > 0)) { 160 if (($request->has('job')) && ($request->get('job') > 0)) {
163 $War_flot = $War_flot->where('job_title_id', $request->get('job')); 161 $War_flot = $War_flot->where('job_title_id', $request->get('job'));
164 } 162 }
165 $War_flot = $War_flot->groupby('job_title_id','position_ship')->get(); 163 $War_flot = $War_flot->groupby('job_title_id','position_ship')->get();
166 $BigFlot[] = $War_flot; 164 $BigFlot[] = $War_flot;
167 }*/ 165 }*/
168 166
169 $BigFlot = Array(); 167 $BigFlot = Array();
170 foreach ($Position as $position) { 168 foreach ($Position as $position) {
171 $WarFlot = DB::table('ad_jobs')-> 169 $WarFlot = DB::table('ad_jobs')->
172 selectRaw('name, count(`ad_jobs`.`id`) as cnt, job_title_id, job_titles.name')-> 170 selectRaw('name, count(`ad_jobs`.`id`) as cnt, job_title_id, job_titles.name')->
173 orderByDesc('job_titles.sort')-> 171 orderByDesc('job_titles.sort')->
174 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')-> 172 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')->
175 where('job_titles.position_id', $position->id); 173 where('job_titles.position_id', $position->id);
176 if (($request->has('job')) && ($request->get('job') > 0)) { 174 if (($request->has('job')) && ($request->get('job') > 0)) {
177 $WarFlot = $WarFlot->where('job_title_id', $request->get('job')); 175 $WarFlot = $WarFlot->where('job_title_id', $request->get('job'));
178 } 176 }
179 $WarFlot = $WarFlot->groupby('job_title_id')->get(); 177 $WarFlot = $WarFlot->groupby('job_title_id')->get();
180 $BigFlot[] = $WarFlot; 178 $BigFlot[] = $WarFlot;
181 } 179 }
182 180
183 if ($request->ajax()) { 181 if ($request->ajax()) {
184 return view('ajax.new_sky', compact('categories', 'BigFlot', 'Position')); 182 return view('ajax.new_sky', compact('categories', 'BigFlot', 'Position'));
185 } else { 183 } else {
186 return view('new_sky', compact('Job_title', 'categories', 'BigFlot', 'Position')); 184 return view('new_sky', compact('Job_title', 'categories', 'BigFlot', 'Position'));
187 } 185 }
188 } 186 }
189 187
190 //Вакансии категория детальная 188 //Вакансии категория детальная
191 public function list_vacancies(Category $categories, Request $request) { 189 public function list_vacancies(Category $categories, Request $request) {
192 if (isset(Auth()->user()->id)) 190 if (isset(Auth()->user()->id))
193 $uid = Auth()->user()->id; 191 $uid = Auth()->user()->id;
194 else 192 else
195 $uid = 0; 193 $uid = 0;
196 194
197 $Query = Ad_employer::with('jobs')-> 195 $Query = Ad_employer::with('jobs')->
198 with('cat')-> 196 with('cat')->
199 with('employer')-> 197 with('employer')->
200 whereHas('jobs_code', function ($query) use ($request) { 198 whereHas('jobs_code', function ($query) use ($request) {
201 if (null !== ($request->get('job')) && ($request->get('job') !== 0)) { 199 if (null !== ($request->get('job')) && ($request->get('job') !== 0)) {
202 $query->where('job_title_id', $request->get('job')); 200 $query->where('job_title_id', $request->get('job'));
203 } 201 }
204 }) 202 })
205 ->select('ad_employers.*'); 203 ->select('ad_employers.*');
206 204
207 205
208 if (isset($categories->id) && ($categories->id > 0)) { 206 if (isset($categories->id) && ($categories->id > 0)) {
209 $Query = $Query->where('category_id', '=', $categories->id); 207 $Query = $Query->where('category_id', '=', $categories->id);
210 $Name_categori = Category::query()->where('id', '=', $categories->id)->get(); 208 $Name_categori = Category::query()->where('id', '=', $categories->id)->get();
211 } else { 209 } else {
212 $Name_categori = ''; 210 $Name_categori = '';
213 } 211 }
214 212
215 if ($request->get('sort')) { 213 if ($request->get('sort')) {
216 $sort = $request->get('sort'); 214 $sort = $request->get('sort');
217 215
218 216
219 switch ($sort) { 217 switch ($sort) {
220 case 'name_up': $Query = $Query->orderBy('name')->orderBy('id'); break; 218 case 'name_up': $Query = $Query->orderBy('name')->orderBy('id'); break;
221 case 'name_down': $Query = $Query->orderByDesc('name')->orderby('id'); break; 219 case 'name_down': $Query = $Query->orderByDesc('name')->orderby('id'); break;
222 case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break; 220 case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break;
223 case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break; 221 case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break;
224 case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break; 222 case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break;
225 default: $Query = $Query->orderBy('id')->orderby('updated_at'); break; 223 default: $Query = $Query->orderBy('id')->orderby('updated_at'); break;
226 } 224 }
227 } 225 }
228 226
229 $Job_title = Job_title::query()->OrderBy('name')->get(); 227 $Job_title = Job_title::query()->OrderBy('name')->get();
230 228
231 $Query_count = $Query->count(); 229 $Query_count = $Query->count();
232 230
233 $Query = $Query->OrderBy('updated_at')->paginate(3); 231 $Query = $Query->OrderBy('updated_at')->paginate(3);
234 232
235 $Reclama = reclame::query()->get(); 233 $Reclama = reclame::query()->get();
236 234
237 235
238 236
239 if ($request->ajax()) { 237 if ($request->ajax()) {
240 if ($request->has('title')) { 238 if ($request->has('title')) {
241 return view('ajax.list_category', compact( 239 return view('ajax.list_category', compact(
242 'Name_categori' 240 'Name_categori'
243 )); 241 ));
244 } else { 242 } else {
245 return view('ajax.list_vacancies', compact('Query', 243 return view('ajax.list_vacancies', compact('Query',
246 'Query_count', 244 'Query_count',
247 'Name_categori', 245 'Name_categori',
248 'Reclama', 246 'Reclama',
249 'categories', 247 'categories',
250 'Job_title', 248 'Job_title',
251 'uid')); 249 'uid'));
252 } 250 }
253 } else { 251 } else {
254 //Вернуть все 252 //Вернуть все
255 return view('list_vacancies', compact('Query', 253 return view('list_vacancies', compact('Query',
256 'Query_count', 254 'Query_count',
257 'Reclama', 255 'Reclama',
258 'Name_categori', 256 'Name_categori',
259 'categories', 257 'categories',
260 'Job_title', 258 'Job_title',
261 'uid')); 259 'uid'));
262 } 260 }
263 } 261 }
264 262
265 // Образование 263 // Образование
266 public function education(Request $request) { 264 public function education(Request $request) {
267 $educations = Education::query(); 265 $educations = Education::query();
268 if (($request->has('search')) && (!empty($request->get('search')))) { 266 if (($request->has('search')) && (!empty($request->get('search')))) {
269 $search = trim($request->get('search')); 267 $search = trim($request->get('search'));
270 $educations = $educations->where('name', 'LIKE', "%$search%"); 268 $educations = $educations->where('name', 'LIKE', "%$search%");
271 } 269 }
272 270
273 if ($request->get('sort')) { 271 if ($request->get('sort')) {
274 $sort = $request->get('sort'); 272 $sort = $request->get('sort');
275 switch ($sort) { 273 switch ($sort) {
276 case 'name_up': $educations = $educations->orderBy('name')->orderBy('id'); break; 274 case 'name_up': $educations = $educations->orderBy('name')->orderBy('id'); break;
277 case 'name_down': $educations = $educations->orderByDesc('name')->orderby('id'); break; 275 case 'name_down': $educations = $educations->orderByDesc('name')->orderby('id'); break;
278 case 'created_at_up': $educations = $educations->OrderBy('created_at')->orderBy('id'); break; 276 case 'created_at_up': $educations = $educations->OrderBy('created_at')->orderBy('id'); break;
279 case 'created_at_down': $educations = $educations->orderByDesc('created_at')->orderBy('id'); break; 277 case 'created_at_down': $educations = $educations->orderByDesc('created_at')->orderBy('id'); break;
280 case 'default': $educations = $educations->orderBy('id')->orderby('updated_at'); break; 278 case 'default': $educations = $educations->orderBy('id')->orderby('updated_at'); break;
281 default: $educations = $educations->orderBy('id')->orderby('updated_at'); break; 279 default: $educations = $educations->orderBy('id')->orderby('updated_at'); break;
282 } 280 }
283 } 281 }
284 282
285 $count_edu = $educations->count(); 283 $count_edu = $educations->count();
286 $educations = $educations->paginate(6); 284 $educations = $educations->paginate(6);
287 if ($request->ajax()) { 285 if ($request->ajax()) {
288 return view('ajax.education', compact('educations')); 286 return view('ajax.education', compact('educations'));
289 } else { 287 } else {
290 return view('education', compact('educations', 'count_edu')); 288 return view('education', compact('educations', 'count_edu'));
291 } 289 }
292 } 290 }
293 291
294 // Контакты 292 // Контакты
295 public function contacts() { 293 public function contacts() {
296 return view('contacts'); 294 return view('contacts');
297 } 295 }
298 296
299 // Вход в личный кабинет 297 // Вход в личный кабинет
300 public function input_login(Request $request) 298 public function input_login(Request $request)
301 { 299 {
302 $params = $request->all(); 300 $params = $request->all();
303 301
304 302
305 $rules = [ 303 $rules = [
306 'email' => 'required|string|email', 304 'email' => 'required|string|email',
307 'password' => 'required|string|min:3|max:25', 305 'password' => 'required|string|min:3|max:25',
308 ]; 306 ];
309 307
310 $messages = [ 308 $messages = [
311 'required' => 'Укажите обязательное поле «:attribute»', 309 'required' => 'Укажите обязательное поле «:attribute»',
312 'email' => 'Введите корректный email', 310 'email' => 'Введите корректный email',
313 'min' => [ 311 'min' => [
314 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 312 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
315 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 313 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
316 ], 314 ],
317 'max' => [ 315 'max' => [
318 'string' => 'Поле «:attribute» должно быть не больше :max символов', 316 'string' => 'Поле «:attribute» должно быть не больше :max символов',
319 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 317 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
320 ], 318 ],
321 ]; 319 ];
322 320
323 $validator = Validator::make($request->all(), $rules, $messages); 321 $validator = Validator::make($request->all(), $rules, $messages);
324 322
325 323
326 if ($validator->fails()) { 324 if ($validator->fails()) {
327 return redirect()->route('index')->with('Error', "Email или пароль невалидный"); 325 return redirect()->route('index')->with('Error', "Email или пароль невалидный");
328 } else { 326 } else {
329 $credentials = $request->only('email', 'password'); 327 $credentials = $request->only('email', 'password');
330 328
331 if (Auth::attempt($credentials, $request->has('remember'))) { 329 if (Auth::attempt($credentials, $request->has('remember'))) {
332 330
333 if (is_null(Auth::user()->email_verified_at)) { 331 if (is_null(Auth::user()->email_verified_at)) {
334 Auth::logout(); 332 Auth::logout();
335 return json_encode(Array("ERROR" => "Адрес почты не подтвержден")); 333 return json_encode(Array("ERROR" => "Адрес почты не подтвержден"));
336 } 334 }
337 335
338 if (Auth::user()->is_worker) { 336 if (Auth::user()->is_worker) {
339 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl())); 337 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));
340 } else { 338 } else {
341 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl())); 339 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));
342 } 340 }
343 341
344 return json_encode(Array("SUCCESS" => "Вы успешно вошли в личный кабинет")); 342 return json_encode(Array("SUCCESS" => "Вы успешно вошли в личный кабинет"));
345 //->route('index') 343 //->route('index')
346 //->with('success', 'Вы вошли в личный кабинет.'); 344 //->with('success', 'Вы вошли в личный кабинет.');
347 } else { 345 } else {
348 return json_encode(Array("ERROR" => "Неверный логин или пароль!")); 346 return json_encode(Array("ERROR" => "Неверный логин или пароль!"));
349 } 347 }
350 } 348 }
351 } 349 }
352 350
353 // Восстановление пароля 351 // Восстановление пароля
354 public function repair_password(Request $request) { 352 public function repair_password(Request $request) {
355 $rules = [ 353 $rules = [
356 'email' => 'required|string|email', 354 'email' => 'required|string|email',
357 ]; 355 ];
358 356
359 $messages = [ 357 $messages = [
360 'required' => 'Укажите обязательное поле «:attribute»', 358 'required' => 'Укажите обязательное поле «:attribute»',
361 'email' => 'Введите корректный email', 359 'email' => 'Введите корректный email',
362 'min' => [ 360 'min' => [
363 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 361 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
364 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 362 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
365 ], 363 ],
366 'max' => [ 364 'max' => [
367 'string' => 'Поле «:attribute» должно быть не больше :max символов', 365 'string' => 'Поле «:attribute» должно быть не больше :max символов',
368 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 366 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
369 ], 367 ],
370 ]; 368 ];
371 369
372 $validator = Validator::make($request->all(), $rules, $messages); 370 $validator = Validator::make($request->all(), $rules, $messages);
373 371
374 if ($validator->fails()) { 372 if ($validator->fails()) {
375 return redirect()->back()->with('Error', "Email невалидный"); 373 return redirect()->back()->with('Error', "Email невалидный");
376 } else { 374 } else {
377 $new_password = Tools::generator_id(10); 375 $new_password = Tools::generator_id(10);
378 $hash_password = Hash::make($new_password); 376 $hash_password = Hash::make($new_password);
379 $user = User::query()->where('email', $request->get('email'))->first(); 377 $user = User::query()->where('email', $request->get('email'))->first();
380 $EditRec = User::find($user->id); 378 $EditRec = User::find($user->id);
381 $EditRec->password = $hash_password; 379 $EditRec->password = $hash_password;
382 $EditRec->save(); 380 $EditRec->save();
383 381
384 foreach ([$request->get('email')] as $recipient) { 382 foreach ([$request->get('email')] as $recipient) {
385 Mail::to($recipient)->send(new MailRepair($new_password)); 383 Mail::to($recipient)->send(new MailRepair($new_password));
386 } 384 }
387 return redirect()->route('index'); 385 return redirect()->route('index');
388 386
389 } 387 }
390 388
391 } 389 }
392 390
393 // Вывод новостей 391 // Вывод новостей
394 public function news(Request $request) { 392 public function news(Request $request) {
395 $Query = News::query(); 393 $Query = News::query();
396 if ($request->has('search')) { 394 if ($request->has('search')) {
397 $search = $request->get('search'); 395 $search = $request->get('search');
398 $Query = $Query->where('title', 'LIKE', "%$search%")-> 396 $Query = $Query->where('title', 'LIKE', "%$search%")->
399 orWhere('text', 'LIKE', "%$search%"); 397 orWhere('text', 'LIKE', "%$search%");
400 } 398 }
401 399
402 if ($request->ajax()) { 400 if ($request->ajax()) {
403 if ($request->get('sort')) { 401 if ($request->get('sort')) {
404 $sort = $request->get('sort'); 402 $sort = $request->get('sort');
405 switch ($sort) { 403 switch ($sort) {
406 case 'name_up': $Query = $Query->orderBy('title')->orderBy('id'); break; 404 case 'name_up': $Query = $Query->orderBy('title')->orderBy('id'); break;
407 case 'name_down': $Query = $Query->orderByDesc('title')->orderby('id'); break; 405 case 'name_down': $Query = $Query->orderByDesc('title')->orderby('id'); break;
408 case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break; 406 case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break;
409 case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break; 407 case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break;
410 case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break; 408 case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break;
411 default: $Query = $Query->orderBy('id')->orderby('updated_at'); break; 409 default: $Query = $Query->orderBy('id')->orderby('updated_at'); break;
412 } 410 }
413 } 411 }
414 } 412 }
415 $Query_count = $Query->count(); 413 $Query_count = $Query->count();
416 $Query = $Query->paginate(6); 414 $Query = $Query->paginate(6);
417 415
418 if ($request->ajax()) { 416 if ($request->ajax()) {
419 return view('ajax.news-list', compact('Query', 'Query_count')); 417 return view('ajax.news-list', compact('Query', 'Query_count'));
420 } else { 418 } else {
421 return view('news-list', compact('Query', 'Query_count')); 419 return view('news-list', compact('Query', 'Query_count'));
422 } 420 }
423 } 421 }
424 422
425 //Детальная новость 423 //Детальная новость
426 public function detail_new(News $new) { 424 public function detail_new(News $new) {
427 // Наборка 425 // Наборка
428 $Query = News::query()->where('id', $new->id)->get(); 426 $Query = News::query()->where('id', $new->id)->get();
429 $title = $Query[0]->title; 427 $title = $Query[0]->title;
430 $All_Query = News::query()->paginate(8); 428 $All_Query = News::query()->paginate(8);
431 return view('detail_new', compact('Query', 'All_Query', 'title')); 429 return view('detail_new', compact('Query', 'All_Query', 'title'));
432 } 430 }
433 } 431 }
434 432