Blame view

app/Http/Controllers/MainController.php 3.22 KB
02a1ed535   Андрей Ларионов   Первый коммит Rek...
1
2
3
  <?php
  
  namespace App\Http\Controllers;
5b68533bb   Андрей Ларионов   Работа над проект...
4
5
6
7
8
  use App\Models\Category;
  use App\Models\Employer;
  use App\Models\Job_title;
  use App\Models\News;
  use App\Models\reclame;
02a1ed535   Андрей Ларионов   Первый коммит Rek...
9
10
11
12
  use Illuminate\Http\Request;
  
  class MainController extends Controller
  {
1d1c16604   Андрей Ларионов   Фрондэнд - главна...
13
      // Главная страница публичной части
02a1ed535   Андрей Ларионов   Первый коммит Rek...
14
      public function index() {
5b68533bb   Андрей Ларионов   Работа над проект...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
          $news = News::query()->orderBy('id')->limit(6)->get();
  
          $categories = Category::query()->selectRaw('count(ad_employers.id) as cnt, categories.*')
              ->join('ad_employers', 'ad_employers.category_id', '=', 'categories.id')
              ->OrderByDesc('created_at')
              ->GroupBy('categories.id')
              ->get();
  
          $employers = Employer::query()->orderBy('id')->limit(20)->get();
  
          return view('index', compact('news', 'categories', 'employers'));
      }
  
      public function vacancies(Request $request) {
          //должности
          $Job_title = Job_title::query()->orderBy('name')->get();
  
          $categories = Category::query()->selectRaw('count(ad_employers.id) as cnt, categories.*')
                      ->selectRaw('min(ad_employers.salary) as min_salary, max(ad_employers.salary) as max_salary')
                      ->join('ad_employers', 'ad_employers.category_id', '=', 'categories.id')
                      ->join('ad_jobs', 'ad_jobs.ad_employer_id', '=', 'ad_employers.id');
  
          //категории и вакансии
          if ($request->ajax()) {
                $categories = $categories->Where('job_title_id', '=', $request->get('job'))
                                          ->OrderByDesc('created_at')
                                          ->GroupBy('categories.id')
                                          ->get();
          } else {
                  $categories = $categories->OrderByDesc('created_at')
                                             ->GroupBy('categories.id')
                                             ->get();
          }
  
          if ($request->ajax()) {
              return view('ajax.vacancies', compact('categories'));
          } else {
              return view('vacancies', compact('Job_title', 'categories'));
          }
      }
  
      //Вакансии категория детальная
      public function list_vacancies(Request $request) {
         $data = $request->all();
  
         if ($data['categories'] == 'all') {
             $Categories_id = 0;
         } else {
              $Categories_id = $data['categories'];
         }
  
         if ($data['job_titles'] == 'all') {
             $job_titles_id = 0;
         } else {
             $job_titles_id = $data['job_titles'];
         }
  
         $Query = Employer::with('jobs')->with('cat')->select('employers.*');
         if ($Categories_id > 0) {
             $Query = $Query->where('category_id', '=', $Categories_id);
             $Name_categori = Category::query()->where('id', '=', $Categories_id)->get();
  
         }
  
         if ($job_titles_id > 0) {
              $Query = $Query->join('ad_jobs', 'job_title_id', '=', $job_titles_id);
         }
  
         // Данные
         $Job_title = Job_title::query()->get();
         $Query = $Query->OrderBy('updated_at')->paginate(15);
         $Reclama = reclame::query()->limit(3)->get();
  
         return view('list_vacancies', compact('Query', 'Reclama', 'Name_categori', 'Job_title'));
02a1ed535   Андрей Ларионов   Первый коммит Rek...
89
90
      }
  }