Commit 51c4e3944dddb1c3be2f5bd45e50eeeef3be951b

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

Update main controller

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

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