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