Commit 7c7dcbe7f12a5846928ccc3051299a2cbd53e651

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

Merge branch 'master' of http://gitlab.nologostudio.ru/alarionov/rekamore-su

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