Commit 4c2bb426124ae9b5314def5ccf22fa525952c0cd

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

небольшая поправочка по категориям специальностях

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