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