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