Commit 24b44fa6c6833642d412c126717582bbc1db5c10

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

майн контроллер

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 165
165 /*$BigFlot = Array(); 166 /*$BigFlot = Array();
166 foreach ($Position as $position) { 167 foreach ($Position as $position) {
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')-> 168 $War_flot = DB::table('ad_jobs')->selectRaw('name, job_titles.id as id_title, count(`ad_jobs`.`id`) as cnt, ad_jobs.position_ship')->
168 orderBy('job_titles.sort')-> 169 orderBy('job_titles.sort')->
169 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')-> 170 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')->
170 where('position_ship', "$position->name"); 171 where('position_ship', "$position->name");
171 if (($request->has('job')) && ($request->get('job') > 0)) { 172 if (($request->has('job')) && ($request->get('job') > 0)) {
172 $War_flot = $War_flot->where('job_title_id', $request->get('job')); 173 $War_flot = $War_flot->where('job_title_id', $request->get('job'));
173 } 174 }
174 $War_flot = $War_flot->groupby('job_title_id','position_ship')->get(); 175 $War_flot = $War_flot->groupby('job_title_id','position_ship')->get();
175 $BigFlot[] = $War_flot; 176 $BigFlot[] = $War_flot;
176 }*/ 177 }*/
177 /* 178 /*
178 $BigFlot = Array(); 179 $BigFlot = Array();
179 foreach ($Position as $position) { 180 foreach ($Position as $position) {
180 $WarFlot = DB::table('ad_jobs')-> 181 $WarFlot = DB::table('ad_jobs')->
181 selectRaw('name, count(`ad_jobs`.`id`) as cnt, job_title_id, job_titles.name')-> 182 selectRaw('name, count(`ad_jobs`.`id`) as cnt, job_title_id, job_titles.name')->
182 orderByDesc('job_titles.sort')-> 183 orderByDesc('job_titles.sort')->
183 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')-> 184 join('job_titles', 'job_titles.id', '=', 'ad_jobs.job_title_id')->
184 where('job_titles.position_id', $position->id); 185 where('job_titles.position_id', $position->id);
185 if (($request->has('job')) && ($request->get('job') > 0)) { 186 if (($request->has('job')) && ($request->get('job') > 0)) {
186 $WarFlot = $WarFlot->where('job_title_id', $request->get('job')); 187 $WarFlot = $WarFlot->where('job_title_id', $request->get('job'));
187 } 188 }
188 $WarFlot = $WarFlot->groupby('job_title_id')->get(); 189 $WarFlot = $WarFlot->groupby('job_title_id')->get();
189 $BigFlot[] = $WarFlot; 190 $BigFlot[] = $WarFlot;
190 } 191 }
191 */ 192 */
192 193
193 $Data = DB::table('job_titles')-> 194 $Data = DB::table('job_titles')->
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 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')->
196 where('categories.is_remove', '=', '0')->
197 where('job_titles.is_remove', '=', '0');
195 if (($request->has('job')) && ($request->get('job') > 0)) { 198 if (($request->has('job')) && ($request->get('job') > 0)) {
196 $Data = $Data->where('job_title_id', $request->get('job')); 199 $Data = $Data->where('job_title_id', $request->get('job'));
197 } 200 }
198 $Data = $Data->leftJoin('ad_jobs', 'ad_jobs.job_title_id', '=', 'job_titles.id')-> 201 $Data = $Data->leftJoin('ad_jobs', 'ad_jobs.job_title_id', '=', 'job_titles.id')->
199 join('categories', 'categories.id', '=', 'job_titles.position_id')-> 202 join('categories', 'categories.id', '=', 'job_titles.position_id')->
200 groupBy('job_titles.id')->orderByDesc('job_titles.position_id')-> 203 groupBy('job_titles.id')->orderByDesc('job_titles.position_id')->
201 orderByDesc('job_titles.sort')->get()->toArray(); 204 orderByDesc('job_titles.sort')->get()->toArray();
202 205
203 $Main_Job = array(); 206 $Main_Job = array();
204 $name_cat = ''; 207 $name_cat = '';
205 foreach ($Data as $it) { 208 foreach ($Data as $it) {
206 $it_arr = (array)$it; 209 $it_arr = (array)$it;
207 if ($name_cat != $it_arr['catname']) 210 if ($name_cat != $it_arr['catname'])
208 $name_cat = $it_arr['catname']; 211 $name_cat = $it_arr['catname'];
209 $Main_Job[$name_cat][] = $it_arr; 212 $Main_Job[$name_cat][] = $it_arr;
210 } 213 }
211 214
212 if ($request->ajax()) { 215 if ($request->ajax()) {
213 return view('ajax.new_sky', compact('categories', 'Main_Job')); 216 return view('ajax.new_sky', compact('categories', 'Main_Job'));
214 } else { 217 } else {
215 return view('new_sky', compact('Job_title', 'categories', 'Main_Job')); 218 return view('new_sky', compact('Job_title', 'categories', 'Main_Job'));
216 } 219 }
217 } 220 }
218 221
219 //Вакансии категория детальная 222 //Вакансии категория детальная
220 public function list_vacancies(Category $categories, Request $request) { 223 public function list_vacancies(Category $categories, Request $request) {
221 if (isset(Auth()->user()->id)) 224 if (isset(Auth()->user()->id))
222 $uid = Auth()->user()->id; 225 $uid = Auth()->user()->id;
223 else 226 else
224 $uid = 0; 227 $uid = 0;
225 228
226 if ($request->get('job') == 0) 229 if ($request->get('job') == 0)
227 $job_search = ''; 230 $job_search = '';
228 else 231 else
229 $job_search = $request->get('job'); 232 $job_search = $request->get('job');
230 233
231 $Query = Ad_employer::with('jobs')-> 234 $Query = Ad_employer::with('jobs')->
232 with('cat')-> 235 with('cat')->
233 with('employer')-> 236 with('employer')->
234 237
235 whereHas('jobs_code', function ($query) use ($job_search) { 238 whereHas('jobs_code', function ($query) use ($job_search) {
236 if (!empty($job_search)) { 239 if (!empty($job_search)) {
237 $query->where('job_title_id', $job_search); 240 $query->where('job_title_id', $job_search);
238 } 241 }
239 })->select('ad_employers.*'); 242 })->select('ad_employers.*');
240 243
241 if (isset($categories->id) && ($categories->id > 0)) { 244 if (isset($categories->id) && ($categories->id > 0)) {
242 $Query = $Query->where('category_id', '=', $categories->id); 245 $Query = $Query->where('category_id', '=', $categories->id);
243 $Name_categori = Category::query()->where('id', '=', $categories->id)->get(); 246 $Name_categori = Category::query()->where('id', '=', $categories->id)->get();
244 } else { 247 } else {
245 $Name_categori = ''; 248 $Name_categori = '';
246 } 249 }
247 250
248 if ($request->get('sort')) { 251 if ($request->get('sort')) {
249 $sort = $request->get('sort'); 252 $sort = $request->get('sort');
250 switch ($sort) { 253 switch ($sort) {
251 case 'name_up': $Query = $Query->orderBy('name')->orderBy('id'); break; 254 case 'name_up': $Query = $Query->orderBy('name')->orderBy('id'); break;
252 case 'name_down': $Query = $Query->orderByDesc('name')->orderby('id'); break; 255 case 'name_down': $Query = $Query->orderByDesc('name')->orderby('id'); break;
253 case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break; 256 case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break;
254 case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break; 257 case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break;
255 case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break; 258 case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break;
256 default: $Query = $Query->orderBy('id')->orderby('updated_at'); break; 259 default: $Query = $Query->orderBy('id')->orderby('updated_at'); break;
257 } 260 }
258 } 261 }
259 262
260 $Job_title = Job_title::query()->OrderBy('name')->get(); 263 $Job_title = Job_title::query()->OrderBy('name')->get();
261 264
262 $Query_count = $Query->count(); 265 $Query_count = $Query->count();
263 266
264 $Query = $Query->OrderBy('updated_at')->paginate(3); 267 $Query = $Query->OrderBy('updated_at')->paginate(3);
265 268
266 $Reclama = reclame::query()->get(); 269 $Reclama = reclame::query()->get();
267 270
268 if ($request->ajax()) { 271 if ($request->ajax()) {
269 if ($request->has('title')) { 272 if ($request->has('title')) {
270 return view('ajax.list_category', compact( 273 return view('ajax.list_category', compact(
271 'Name_categori' 274 'Name_categori'
272 )); 275 ));
273 } else { 276 } else {
274 return view('ajax.list_vacancies', compact('Query', 277 return view('ajax.list_vacancies', compact('Query',
275 'Query_count', 278 'Query_count',
276 'Name_categori', 279 'Name_categori',
277 'Reclama', 280 'Reclama',
278 'categories', 281 'categories',
279 'Job_title', 282 'Job_title',
280 'uid')); 283 'uid'));
281 } 284 }
282 } else { 285 } else {
283 //Вернуть все 286 //Вернуть все
284 return view('list_vacancies', compact('Query', 287 return view('list_vacancies', compact('Query',
285 'Query_count', 288 'Query_count',
286 'Reclama', 289 'Reclama',
287 'Name_categori', 290 'Name_categori',
288 'categories', 291 'categories',
289 'Job_title', 292 'Job_title',
290 'uid')); 293 'uid'));
291 } 294 }
292 } 295 }
293 296
294 // Образование 297 // Образование
295 public function education(Request $request) { 298 public function education(Request $request) {
296 $educations = Education::query(); 299 $educations = Education::query();
297 if (($request->has('search')) && (!empty($request->get('search')))) { 300 if (($request->has('search')) && (!empty($request->get('search')))) {
298 $search = trim($request->get('search')); 301 $search = trim($request->get('search'));
299 $educations = $educations->where('name', 'LIKE', "%$search%"); 302 $educations = $educations->where('name', 'LIKE', "%$search%");
300 } 303 }
301 304
302 if ($request->get('sort')) { 305 if ($request->get('sort')) {
303 $sort = $request->get('sort'); 306 $sort = $request->get('sort');
304 switch ($sort) { 307 switch ($sort) {
305 case 'name_up': $educations = $educations->orderBy('name')->orderBy('id'); break; 308 case 'name_up': $educations = $educations->orderBy('name')->orderBy('id'); break;
306 case 'name_down': $educations = $educations->orderByDesc('name')->orderby('id'); break; 309 case 'name_down': $educations = $educations->orderByDesc('name')->orderby('id'); break;
307 case 'created_at_up': $educations = $educations->OrderBy('created_at')->orderBy('id'); break; 310 case 'created_at_up': $educations = $educations->OrderBy('created_at')->orderBy('id'); break;
308 case 'created_at_down': $educations = $educations->orderByDesc('created_at')->orderBy('id'); break; 311 case 'created_at_down': $educations = $educations->orderByDesc('created_at')->orderBy('id'); break;
309 case 'default': $educations = $educations->orderBy('id')->orderby('updated_at'); break; 312 case 'default': $educations = $educations->orderBy('id')->orderby('updated_at'); break;
310 default: $educations = $educations->orderBy('id')->orderby('updated_at'); break; 313 default: $educations = $educations->orderBy('id')->orderby('updated_at'); break;
311 } 314 }
312 } 315 }
313 316
314 $count_edu = $educations->count(); 317 $count_edu = $educations->count();
315 $educations = $educations->paginate(6); 318 $educations = $educations->paginate(6);
316 if ($request->ajax()) { 319 if ($request->ajax()) {
317 return view('ajax.education', compact('educations')); 320 return view('ajax.education', compact('educations'));
318 } else { 321 } else {
319 return view('education', compact('educations', 'count_edu')); 322 return view('education', compact('educations', 'count_edu'));
320 } 323 }
321 } 324 }
322 325
323 // Контакты 326 // Контакты
324 public function contacts() { 327 public function contacts() {
325 return view('contacts'); 328 return view('contacts');
326 } 329 }
327 330
328 // Вход в личный кабинет 331 // Вход в личный кабинет
329 public function input_login(Request $request) 332 public function input_login(Request $request)
330 { 333 {
331 $params = $request->all(); 334 $params = $request->all();
332 335
333 336
334 $rules = [ 337 $rules = [
335 'email' => 'required|string|email', 338 'email' => 'required|string|email',
336 'password' => 'required|string|min:3|max:25', 339 'password' => 'required|string|min:3|max:25',
337 ]; 340 ];
338 341
339 $messages = [ 342 $messages = [
340 'required' => 'Укажите обязательное поле «:attribute»', 343 'required' => 'Укажите обязательное поле «:attribute»',
341 'email' => 'Введите корректный email', 344 'email' => 'Введите корректный email',
342 'min' => [ 345 'min' => [
343 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 346 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
344 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 347 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
345 ], 348 ],
346 'max' => [ 349 'max' => [
347 'string' => 'Поле «:attribute» должно быть не больше :max символов', 350 'string' => 'Поле «:attribute» должно быть не больше :max символов',
348 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 351 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
349 ], 352 ],
350 ]; 353 ];
351 354
352 $validator = Validator::make($request->all(), $rules, $messages); 355 $validator = Validator::make($request->all(), $rules, $messages);
353 356
354 357
355 if ($validator->fails()) { 358 if ($validator->fails()) {
356 return json_encode(Array("ERROR" => "Email или пароль невалидный!")); 359 return json_encode(Array("ERROR" => "Email или пароль невалидный!"));
357 //redirect()->route('index')->with('Error', "Email или пароль невалидный"); 360 //redirect()->route('index')->with('Error', "Email или пароль невалидный");
358 } else { 361 } else {
359 $credentials = $request->only('email', 'password'); 362 $credentials = $request->only('email', 'password');
360 363
361 if (Auth::attempt($credentials, $request->has('remember'))) { 364 if (Auth::attempt($credentials, $request->has('remember'))) {
362 365
363 if (is_null(Auth::user()->email_verified_at)) { 366 if (is_null(Auth::user()->email_verified_at)) {
364 Auth::logout(); 367 Auth::logout();
365 return json_encode(Array("ERROR" => "Адрес почты не подтвержден")); 368 return json_encode(Array("ERROR" => "Адрес почты не подтвержден"));
366 } 369 }
367 370
368 if (Auth::user()->is_worker) { 371 if (Auth::user()->is_worker) {
369 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl())); 372 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));
370 } else { 373 } else {
371 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl())); 374 return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));
372 } 375 }
373 376
374 return json_encode(Array("SUCCESS" => "Вы успешно вошли в личный кабинет")); 377 return json_encode(Array("SUCCESS" => "Вы успешно вошли в личный кабинет"));
375 //->route('index') 378 //->route('index')
376 //->with('success', 'Вы вошли в личный кабинет.'); 379 //->with('success', 'Вы вошли в личный кабинет.');
377 } else { 380 } else {
378 return json_encode(Array("ERROR" => "Неверный логин или пароль!")); 381 return json_encode(Array("ERROR" => "Неверный логин или пароль!"));
379 } 382 }
380 } 383 }
381 } 384 }
382 385
383 // Восстановление пароля 386 // Восстановление пароля
384 public function repair_password(Request $request) { 387 public function repair_password(Request $request) {
385 $rules = [ 388 $rules = [
386 'email' => 'required|string|email', 389 'email' => 'required|string|email',
387 ]; 390 ];
388 391
389 $messages = [ 392 $messages = [
390 'required' => 'Укажите обязательное поле «:attribute»', 393 'required' => 'Укажите обязательное поле «:attribute»',
391 'email' => 'Введите корректный email', 394 'email' => 'Введите корректный email',
392 'min' => [ 395 'min' => [
393 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 396 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
394 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 397 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
395 ], 398 ],
396 'max' => [ 399 'max' => [
397 'string' => 'Поле «:attribute» должно быть не больше :max символов', 400 'string' => 'Поле «:attribute» должно быть не больше :max символов',
398 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 401 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
399 ], 402 ],
400 ]; 403 ];
401 404
402 $validator = Validator::make($request->all(), $rules, $messages); 405 $validator = Validator::make($request->all(), $rules, $messages);
403 406
404 if ($validator->fails()) { 407 if ($validator->fails()) {
405 return redirect()->back()->with('Error', "Email невалидный"); 408 return redirect()->back()->with('Error', "Email невалидный");
406 } else { 409 } else {
407 $new_password = Tools::generator_id(10); 410 $new_password = Tools::generator_id(10);
408 $hash_password = Hash::make($new_password); 411 $hash_password = Hash::make($new_password);
409 $user = User::query()->where('email', $request->get('email'))->first(); 412 $user = User::query()->where('email', $request->get('email'))->first();
410 $EditRec = User::find($user->id); 413 $EditRec = User::find($user->id);
411 $EditRec->password = $hash_password; 414 $EditRec->password = $hash_password;
412 $EditRec->save(); 415 $EditRec->save();
413 416
414 foreach ([$request->get('email')] as $recipient) { 417 foreach ([$request->get('email')] as $recipient) {
415 Mail::to($recipient)->send(new MailRepair($new_password)); 418 Mail::to($recipient)->send(new MailRepair($new_password));
416 } 419 }
417 return redirect()->route('index'); 420 return redirect()->route('index');
418 421
419 } 422 }
420 423
421 } 424 }
422 425
423 // Вывод новостей 426 // Вывод новостей
424 public function news(Request $request) { 427 public function news(Request $request) {
425 $Query = News::query(); 428 $Query = News::query();
426 if ($request->has('search')) { 429 if ($request->has('search')) {
427 $search = $request->get('search'); 430 $search = $request->get('search');
428 $Query = $Query->where('title', 'LIKE', "%$search%")-> 431 $Query = $Query->where('title', 'LIKE', "%$search%")->
429 orWhere('text', 'LIKE', "%$search%"); 432 orWhere('text', 'LIKE', "%$search%");
430 } 433 }
431 434
432 if ($request->ajax()) { 435 if ($request->ajax()) {
433 if ($request->get('sort')) { 436 if ($request->get('sort')) {
434 $sort = $request->get('sort'); 437 $sort = $request->get('sort');
435 switch ($sort) { 438 switch ($sort) {
436 case 'name_up': $Query = $Query->orderBy('title')->orderBy('id'); break; 439 case 'name_up': $Query = $Query->orderBy('title')->orderBy('id'); break;
437 case 'name_down': $Query = $Query->orderByDesc('title')->orderby('id'); break; 440 case 'name_down': $Query = $Query->orderByDesc('title')->orderby('id'); break;
438 case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break; 441 case 'created_at_up': $Query = $Query->OrderBy('created_at')->orderBy('id'); break;
439 case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break; 442 case 'created_at_down': $Query = $Query->orderByDesc('created_at')->orderBy('id'); break;
440 case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break; 443 case 'default': $Query = $Query->orderBy('id')->orderby('updated_at'); break;
441 default: $Query = $Query->orderBy('id')->orderby('updated_at'); break; 444 default: $Query = $Query->orderBy('id')->orderby('updated_at'); break;
442 } 445 }
443 } 446 }
444 } 447 }
445 $Query_count = $Query->count(); 448 $Query_count = $Query->count();
446 $Query = $Query->paginate(6); 449 $Query = $Query->paginate(6);
447 450
448 if ($request->ajax()) { 451 if ($request->ajax()) {
449 return view('ajax.news-list', compact('Query', 'Query_count')); 452 return view('ajax.news-list', compact('Query', 'Query_count'));
450 } else { 453 } else {
451 return view('news-list', compact('Query', 'Query_count')); 454 return view('news-list', compact('Query', 'Query_count'));
452 } 455 }
453 } 456 }
454 457
455 //Детальная новость 458 //Детальная новость
456 public function detail_new(News $new) { 459 public function detail_new(News $new) {
457 // Наборка 460 // Наборка
458 $Query = News::query()->where('id', $new->id)->get(); 461 $Query = News::query()->where('id', $new->id)->get();
459 $title = $Query[0]->title; 462 $title = $Query[0]->title;
460 $All_Query = News::query()->paginate(8); 463 $All_Query = News::query()->paginate(8);
461 return view('detail_new', compact('Query', 'All_Query', 'title')); 464 return view('detail_new', compact('Query', 'All_Query', 'title'));
462 } 465 }
463 } 466 }