Commit 00652ea5794c5fcfdfd58d259a3aecdedf5983f6

Authored by Андрей Ларионов
1 parent 4452df3267

Оптимизация запросов БД, справочник образование, модификация админки по просьбе заказчика

Showing 26 changed files with 736 additions and 31 deletions Side-by-side Diff

app/Http/Controllers/Admin/Ad_EmployersController.php
... ... @@ -18,7 +18,7 @@ class Ad_EmployersController extends Controller
18 18 public function index(Request $request)
19 19 {
20 20 $title = 'Админка - Вакансии работодателей';
21   - $ad_employers = Ad_employer::where('is_remove', '0')->paginate(15);
  21 + $ad_employers = Ad_employer::with('employer')->with('jobs')->where('is_remove', '0')->paginate(15);
22 22  
23 23 return view('admin.ad_employers.index', compact('ad_employers', 'title'));
24 24  
app/Http/Controllers/Admin/CategoryEmpController.php
... ... @@ -3,6 +3,7 @@
3 3 namespace App\Http\Controllers\Admin;
4 4  
5 5 use App\Http\Controllers\Controller;
  6 +use App\Http\Requests\CategoryEmpRequest;
6 7 use App\Models\CategoryEmp;
7 8 use Illuminate\Http\Request;
8 9  
... ... @@ -35,7 +36,7 @@ class CategoryEmpController extends Controller
35 36 * @param \Illuminate\Http\Request $request
36 37 * @return \Illuminate\Http\Response
37 38 */
38   - public function store(Request $request)
  39 + public function store(CategoryEmpRequest $request)
39 40 {
40 41 CategoryEmp::create($request->all());
41 42 return redirect()->route('admin.category-emp.index');
... ... @@ -70,7 +71,7 @@ class CategoryEmpController extends Controller
70 71 * @param \App\Models\CategoryEmp $categoryEmp
71 72 * @return \Illuminate\Http\Response
72 73 */
73   - public function update(Request $request, CategoryEmp $category_emp)
  74 + public function update(CategoryEmpRequest $request, CategoryEmp $category_emp)
74 75 {
75 76 $category_emp->update($request->all());
76 77 return redirect()->route('admin.category-emp.index');
app/Http/Controllers/Admin/EducationController.php
... ... @@ -0,0 +1,91 @@
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Admin;
  4 +
  5 +use App\Http\Controllers\Controller;
  6 +use App\Http\Requests\EducationRequest;
  7 +use App\Models\Education;
  8 +use Illuminate\Http\Request;
  9 +
  10 +class EducationController extends Controller
  11 +{
  12 + /**
  13 + * Display a listing of the resource.
  14 + *
  15 + * @return \Illuminate\Http\Response
  16 + */
  17 + public function index()
  18 + {
  19 + $education = Education::query()->active()->paginate(15);
  20 + return view('admin.education.index', compact('education'));
  21 + }
  22 +
  23 + /**
  24 + * Show the form for creating a new resource.
  25 + *
  26 + * @return \Illuminate\Http\Response
  27 + */
  28 + public function create()
  29 + {
  30 + return view('admin.education.add');
  31 + }
  32 +
  33 + /**
  34 + * Store a newly created resource in storage.
  35 + *
  36 + * @param \Illuminate\Http\Request $request
  37 + * @return \Illuminate\Http\Response
  38 + */
  39 + public function store(EducationRequest $request)
  40 + {
  41 + Education::create($request->all());
  42 + return redirect()->route('admin.education.index');
  43 + }
  44 +
  45 + /**
  46 + * Display the specified resource.
  47 + *
  48 + * @param \App\Models\Education $education
  49 + * @return \Illuminate\Http\Response
  50 + */
  51 + public function show(Education $education)
  52 + {
  53 + //
  54 + }
  55 +
  56 + /**
  57 + * Show the form for editing the specified resource.
  58 + *
  59 + * @param \App\Models\Education $education
  60 + * @return \Illuminate\Http\Response
  61 + */
  62 + public function edit(Education $education)
  63 + {
  64 + return view('admin.education.edit', compact('education'));
  65 + }
  66 +
  67 + /**
  68 + * Update the specified resource in storage.
  69 + *
  70 + * @param \Illuminate\Http\Request $request
  71 + * @param \App\Models\Education $education
  72 + * @return \Illuminate\Http\Response
  73 + */
  74 + public function update(EducationRequest $request, Education $education)
  75 + {
  76 + $education->update($request->all());
  77 + return redirect()->route('admin.education.index');
  78 + }
  79 +
  80 + /**
  81 + * Remove the specified resource from storage.
  82 + *
  83 + * @param \App\Models\Education $education
  84 + * @return \Illuminate\Http\Response
  85 + */
  86 + public function destroy(Education $education)
  87 + {
  88 + $education->update(['is_remove' => 1]);
  89 + return redirect()->route('admin.education.index');
  90 + }
  91 +}
app/Http/Controllers/Admin/EmployersController.php
... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
5 5 use App\Http\Controllers\Controller;
6 6 use App\Models\Ad_employer;
7 7 use App\Models\Answer;
  8 +use App\Models\CategoryEmp;
8 9 use App\Models\Employer;
9 10 use App\Models\Static_ad;
10 11 use App\Models\User;
... ... @@ -35,7 +36,7 @@ class EmployersController extends Controller
35 36 });
36 37 }*/
37 38  
38   - $users = User::select(['users.*','users.id as usr_id', 'emp.id as emp_id', 'emp.*'])->join('employers as emp','emp.user_id','users.id')
  39 + $users = User::with('employers')->select(['users.*','users.id as usr_id', 'emp.id as emp_id', 'emp.*'])->join('employers as emp','emp.user_id','users.id')
39 40 ->where('users.is_worker', '0');
40 41 $all_employer = $users->count();
41 42 $find_key = "";
... ... @@ -60,7 +61,8 @@ class EmployersController extends Controller
60 61 }
61 62  
62 63 public function form_update_employer(Employer $employer) {
63   - return view('admin.employer.edit', compact('employer'));
  64 + $select_category = CategoryEmp::query()->active()->get();
  65 + return view('admin.employer.edit', compact('employer', 'select_category'));
64 66 }
65 67  
66 68 public function update_employer(Employer $employer, Request $request)
... ... @@ -75,6 +77,8 @@ class EmployersController extends Controller
75 77 unset($params['oficial_status']);
76 78 unset($params['social_is']);
77 79 unset($params['sending_is']);
  80 + unset($params['category']);
  81 + unset($params['comment_admin']);
78 82  
79 83 $rules = [
80 84 'name' => 'required|string|max:255',
... ... @@ -112,6 +116,8 @@ class EmployersController extends Controller
112 116 $employer->oficial_status = $request->oficial_status;
113 117 $employer->social_is = $request->social_is;
114 118 $employer->sending_is = $request->sending_is;
  119 + $employer->category = $request->category;
  120 + $employer->comment_admin = $request->comment_admin;
115 121  
116 122 if ($request->has('logo')) {
117 123 if (!empty($employer->logo)) {
... ... @@ -129,6 +135,23 @@ class EmployersController extends Controller
129 135 }
130 136 }
131 137  
  138 + // Удаление работодателя, вакансий и профиля юзера
  139 + public function delete_employer(Employer $employer, User $user) {
  140 + try {
  141 + if (!empty($employer)) {
  142 + $employer->ads()->delete();
  143 + if (!empty($employer->logo)) {
  144 + Storage::delete($employer->logo);
  145 + }
  146 + $employer->delete();
  147 + }
  148 + } finally {
  149 + $user->delete();
  150 + }
  151 +
  152 + return redirect()->route('admin.employers')->with('success', 'Данные были удалены о работодателе');
  153 + }
  154 +
132 155 // кабинет - отзывы о работодателе для модерации
133 156 public function answers(Request $request) {
134 157 if ($request->ajax()) {
app/Http/Controllers/Admin/GroupsController.php
... ... @@ -17,7 +17,7 @@ class GroupsController extends Controller
17 17  
18 18 // индексная страница
19 19 public function index() {
20   - $groups = Group_user::query()->active()->paginate(15);
  20 + $groups = Group_user::with('user')->with('ingroup')->active()->paginate(15);
21 21 return view('admin.groups.index', compact('groups'));
22 22 }
23 23  
app/Http/Controllers/Admin/MsgAnswersController.php
... ... @@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Validator;
13 13 class MsgAnswersController extends Controller
14 14 {
15 15 public function messages() {
16   - $Msgs = Message::query()->orderByDesc('created_at')->paginate(25);
  16 + $Msgs = Message::with('user_from')->with('user_to')->with('response')->orderByDesc('created_at')->paginate(25);
17 17  
18 18 return view('admin.messages', compact('Msgs'));
19 19 }
... ... @@ -28,7 +28,8 @@ class MsgAnswersController extends Controller
28 28 $id_admin = Auth::user()->id;
29 29 $users = User::query()->OrderBy('name')->get();
30 30  
31   - $Msgs = Message::query()->where('user_id', '=', $id_admin)
  31 + $Msgs = Message::with('user_from')->with('user_to')->with('response')
  32 + ->where('user_id', '=', $id_admin)
32 33 ->orWhere('to_user_id', '=', $id_admin)
33 34 ->orderByDesc('created_at')->paginate(5);
34 35  
app/Http/Controllers/Admin/WorkersController.php
... ... @@ -21,7 +21,7 @@ class WorkersController extends Controller
21 21 $user->update($request->all());
22 22 }
23 23  
24   - $users = User::where('is_worker', '1');
  24 + $users = User::with('workers')->where('is_worker', '1');
25 25 $find_key = "";
26 26 if (isset($request->find)) {
27 27 $find_key = $request->find;
app/Http/Requests/CategoryEmpRequest.php
... ... @@ -0,0 +1,45 @@
  1 +<?php
  2 +
  3 +namespace App\Http\Requests;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class CategoryEmpRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array<string, mixed>
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'name' => 'required|min:3|max:255',
  28 + ];
  29 + }
  30 +
  31 + public function messages() {
  32 + return [
  33 + 'required' => 'Поле :attribute обязательно для ввода',
  34 + 'min' => [
  35 + 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
  36 + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
  37 + ],
  38 + 'max' => [
  39 + 'string' => 'Поле «:attribute» должно быть не больше :max символов',
  40 + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
  41 + ],
  42 +
  43 + ];
  44 + }
  45 +}
app/Http/Requests/EducationRequest.php
... ... @@ -0,0 +1,45 @@
  1 +<?php
  2 +
  3 +namespace App\Http\Requests;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class EducationRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array<string, mixed>
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'name' => 'required|min:3|max:255',
  28 + ];
  29 + }
  30 +
  31 + public function messages() {
  32 + return [
  33 + 'required' => 'Поле :attribute обязательно для ввода',
  34 + 'min' => [
  35 + 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
  36 + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
  37 + ],
  38 + 'max' => [
  39 + 'string' => 'Поле «:attribute» должно быть не больше :max символов',
  40 + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
  41 + ],
  42 +
  43 + ];
  44 + }
  45 +}
app/Models/Education.php
... ... @@ -0,0 +1,20 @@
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +use Illuminate\Database\Eloquent\Factories\HasFactory;
  6 +use Illuminate\Database\Eloquent\Model;
  7 +
  8 +class Education extends Model
  9 +{
  10 + use HasFactory;
  11 +
  12 + protected $fillable = [
  13 + 'name',
  14 + 'is_remove'
  15 + ];
  16 +
  17 + public function scopeActive($query) {
  18 + return $query->where('is_remove', '=', '0');
  19 + }
  20 +}
app/Providers/MyServiceProvider.php
... ... @@ -48,7 +48,7 @@ class MyServiceProvider extends ServiceProvider
48 48 }
49 49 );
50 50  
51   - $views2 = ['layout.admin'];
  51 + $views2 = ['layout.admin', 'admin.index'];
52 52  
53 53 View::composer($views2,
54 54 function($view){
... ... @@ -59,7 +59,7 @@ class MyServiceProvider extends ServiceProvider
59 59 '), ['uid' => $id]
60 60 );
61 61  
62   - $view->with(['MsgCount' => $query[0]->MsgCount]);
  62 + $view->with(['MsgCount' => $query[0]->MsgCount, 'UserId' => $id]);
63 63 }
64 64 );
65 65 }
database/migrations/2023_10_03_114608_create_education_table.php
... ... @@ -0,0 +1,33 @@
  1 +<?php
  2 +
  3 +use Illuminate\Database\Migrations\Migration;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Support\Facades\Schema;
  6 +
  7 +return new class extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::create('education', function (Blueprint $table) {
  17 + $table->id();
  18 + $table->string('name', 255)->nullable(false);
  19 + $table->boolean('is_remove')->default(false);
  20 + $table->timestamps();
  21 + });
  22 + }
  23 +
  24 + /**
  25 + * Reverse the migrations.
  26 + *
  27 + * @return void
  28 + */
  29 + public function down()
  30 + {
  31 + Schema::dropIfExists('education');
  32 + }
  33 +};
database/migrations/2023_10_03_114801_alter_table_workers.php
... ... @@ -0,0 +1,32 @@
  1 +<?php
  2 +
  3 +use Illuminate\Database\Migrations\Migration;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Support\Facades\Schema;
  6 +
  7 +return new class extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::table('workers', function (Blueprint $table) {
  17 + $table->string('education', 255)->default('Не указано');
  18 + });
  19 + }
  20 +
  21 + /**
  22 + * Reverse the migrations.
  23 + *
  24 + * @return void
  25 + */
  26 + public function down()
  27 + {
  28 + Schema::table('workers', function (Blueprint $table) {
  29 + $table->dropColumn('education');
  30 + });
  31 + }
  32 +};
resources/views/admin/education/add.blade.php
... ... @@ -0,0 +1,7 @@
  1 +@extends('layout.admin', ['title' => 'Админка - Добавление образования'])
  2 +
  3 +@section('content')
  4 + <form method="POST" action="{{ route('admin.education.store') }}">
  5 + @include('admin.education.form')
  6 + </form>
  7 +@endsection
resources/views/admin/education/edit.blade.php
... ... @@ -0,0 +1,7 @@
  1 +@extends('layout.admin', ['title' => 'Админка - Редактирование образования'])
  2 +
  3 +@section('content')
  4 + <form method="POST" action="{{ route('admin.education.update', ['education' => $education->id]) }}">
  5 + @include('admin.education.form')
  6 + </form>
  7 +@endsection
resources/views/admin/education/form.blade.php
... ... @@ -0,0 +1,32 @@
  1 +@csrf
  2 +
  3 +@isset($education)
  4 + @method('PUT')
  5 +@endisset
  6 +
  7 +<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
  8 + <label class="block text-sm">
  9 + <span class="text-gray-700 dark:text-gray-400">Имя категории</span>
  10 + <input name="name" id="name"
  11 + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input"
  12 + placeholder="Имя категории" value="{{ old('name') ?? $education->name ?? '' }}"
  13 + />
  14 + @error('name')
  15 + <span class="text-xs text-red-600 dark:text-red-400">
  16 + {{ $message }}
  17 + </span>
  18 + @enderror
  19 + </label><br>
  20 +
  21 + <div class="flex flex-col flex-wrap mb-4 space-y-4 md:flex-row md:items-end md:space-x-4">
  22 + <div>
  23 + <button type="submit" class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple">
  24 + Сохранить
  25 + </button>
  26 + <a href="{{ route('admin.education.index') }}"
  27 + class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple"
  28 + style="display: -webkit-inline-box; height: 30px!important;"
  29 + >Назад</a>
  30 + </div>
  31 + </div>
  32 +</div>
resources/views/admin/education/index.blade.php
... ... @@ -0,0 +1,61 @@
  1 +@extends('layout.admin', ['title' => 'Админка - Справочник образование'])
  2 +
  3 +@section('script')
  4 +
  5 +@endsection
  6 +
  7 +@section('search')
  8 +
  9 +@endsection
  10 +
  11 +@section('content')
  12 +
  13 + <a href="{{ route('admin.education.create') }}" style="width: 195px" class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple">
  14 + Добавить образование
  15 + </a>
  16 + <br>
  17 + <div class="w-full overflow-hidden rounded-lg shadow-xs" id="ajax_block">
  18 +
  19 + <div class="w-full overflow-x-auto">
  20 + <table class="w-full whitespace-no-wrap">
  21 + <thead>
  22 + <tr
  23 + class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800"
  24 + >
  25 + <th class="px-4 py-3">№</th>
  26 + <th class="px-4 py-3">Название образования</th>
  27 + <th class="px-4 py-3">Дата создания</th>
  28 + <th class="px-4 py-3">Редактировать</th>
  29 + </tr>
  30 + </thead>
  31 + <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
  32 + @foreach($education as $cat)
  33 + <tr class="text-gray-700 dark:text-gray-400">
  34 + <td class="px-4 py-3">
  35 + {{$cat->id}}
  36 + </td>
  37 + <td class="px-4 py-3">
  38 + {{$cat->name}}
  39 + </td>
  40 + <td class="px-4 py-3">
  41 + {{$cat->created_at}}
  42 + </td>
  43 + <td class="px-4 py-3 text-sm_">
  44 + <form action="{{ route('admin.education.destroy', ['education' => $cat->id]) }}" method="POST">
  45 + <a href="{{ route('admin.education.edit', ['education' => $cat->id]) }}">Изменить</a> |
  46 + @csrf
  47 + @method('DELETE')
  48 + <input class="btn btn-danger" type="submit" value="Удалить"/>
  49 + </form>
  50 + </td>
  51 + </tr>
  52 + @endforeach
  53 + </tbody>
  54 + </table>
  55 + </div>
  56 +
  57 + <div class="grid px-4 py-3 text-xs font-semibold tracking-wide text-gray-500 uppercase border-t dark:border-gray-700 bg-gray-50 sm:grid-cols-9 dark:text-gray-400 dark:bg-gray-800">
  58 + <?=$education->appends($_GET)->links('admin.pagginate'); ?>
  59 + </div>
  60 + </div>
  61 +@endsection
resources/views/admin/employer/edit.blade.php
... ... @@ -107,6 +107,37 @@
107 107 >{{ old('text') ?? $employer->text ?? '' }}</textarea>
108 108 </label>
109 109  
  110 + <hr>
  111 +
  112 + <label class="block mt-4 text-sm">
  113 + <span class="text-gray-700 dark:text-gray-400">Категории</span>
  114 +
  115 + <select name="category" id="category" class="form-control">
  116 + @foreach($select_category as $cat)
  117 + <option value="{{ $cat->name }}"
  118 + @isset($employer)
  119 + @if($cat->name == $employer->category)
  120 + selected
  121 + @endif
  122 + @endisset
  123 + >{{ $cat->name }}</option>
  124 + @endforeach
  125 + </select>
  126 +
  127 + @error('category')
  128 + <div class="alert alert-danger">{{ $message }}</div>
  129 + @enderror
  130 + </label>
  131 +
  132 + <label class="block mt-4 text-sm">
  133 + <span class="text-gray-700 dark:text-gray-400">Комментарий админа</span>
  134 + <textarea name="comment_admin" id="comment_admin"
  135 + class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-textarea focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray"
  136 + rows="3"
  137 + placeholder="Комментарий админа"
  138 + >{{ old('comment_admin') ?? $employer->comment_admin ?? '' }}</textarea>
  139 + </label>
  140 +
110 141 </div>
111 142 <div id="content-2">
112 143 <label class="block text-sm">
resources/views/admin/employer/index.blade.php
... ... @@ -74,10 +74,10 @@
74 74 <th class="px-4 py-3">№</th>
75 75 <th class="px-4 py-3">Название компании</th>
76 76 <th class="px-4 py-3">Email/Телефон</th>
77   - <th class="px-4 py-3">Имя</th>
  77 + <th class="px-4 py-3">Категория</th>
  78 + <th class="px-4 py-3">Комментарий</th>
78 79 <th class="px-4 py-3">Дата регистрации</th>
79   - <th class="px-4 py-3">Изменить</th>
80   - <th class="px-4 py-3">Бан</th>
  80 + <th class="px-4 py-3">Редакт.</th>
81 81 </tr>
82 82 </thead>
83 83 <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
... ... @@ -107,21 +107,29 @@
107 107  
108 108 </td>
109 109 <td class="px-4 py-3 text-sm">
110   - {{ $user->name_man }} ({{ $user->usr_id }})
  110 + {{ $user->category }}
  111 + </td>
  112 + <td class="px-4 py-3 text-sm">
  113 + {{ $user->comment_admin }}
111 114 </td>
112 115 <td class="px-4 py-3 text-sm">
113 116 {{ $user->created_at }}
114 117 </td>
115 118 <td class="px-4 py-3 text-sm">
116 119 @if (!empty($user->emp_id))
117   - <a href="{{ route('admin.employer-profile', ['employer' => $user->emp_id]) }}">Изменить</a>
  120 + <form action="{{ route('admin.delete-employer', ['employer' => $user->emp_id, 'user' => $user->user_id]) }}" method="POST">
  121 + <a href="{{ route('admin.employer-profile', ['employer' => $user->emp_id]) }}">Изменить</a> |
  122 + @csrf
  123 + @method('DELETE')
  124 + <input class="btn btn-danger" type="submit" value="Удалить"/>
  125 + </form>
118 126 @endif
119 127 </td>
120   - <td class="px-4 py-3 text-sm">
  128 + <!--<td class="px-4 py-3 text-sm">
121 129 @if ($user->usr_id > 1)
122 130 <input type="checkbox" class="checkban" value="{{$user->usr_id}}" name="ban_{{$user->usr_id}}" {{ ($user->is_ban) ? "checked" : "" }}/>
123 131 @endif
124   - </td>
  132 + </td>-->
125 133 </tr>
126 134 @endforeach
127 135 </tbody>
resources/views/admin/index.blade.php
... ... @@ -103,9 +103,15 @@
103 103 ></div>
104 104 </div>
105 105 <div>
106   - <p class="font-semibold"><a href="{{ route('admin.users') }}">Пользователи</a></p>
  106 + <p class="font-semibold">
  107 + @if ($UserId == 1)
  108 + <a href="{{ route('admin.users') }}">Пользователи</a>
  109 + @else
  110 + Пользователи
  111 + @endif
  112 + </p>
107 113 <p class="text-xs text-gray-600 dark:text-gray-400">
108   - Все пользователи сайта
  114 + Все пользователи сайта. Управление ими. Только для разработчика!
109 115 </p>
110 116 </div>
111 117 </div>
... ... @@ -114,8 +120,8 @@
114 120 users
115 121 </td>
116 122 <td class="px-4 py-3 text-xs">
117   - <span class="px-2 py-1 font-semibold leading-tight text-green-700 bg-green-100 rounded-full dark:bg-green-700 dark:text-green-100">
118   - Доступно
  123 + <span class="px-2 py-1 font-semibold leading-tight text-orange-700 bg-orange-100 rounded-full dark:text-white dark:bg-orange-600">
  124 + Недоступно
119 125 </span>
120 126 <!--<span class="px-2 py-1 font-semibold leading-tight text-orange-700 bg-orange-100 rounded-full dark:text-white dark:bg-orange-600">
121 127 Недоступно
... ... @@ -214,6 +220,33 @@
214 220 <div class="absolute inset-0 rounded-full shadow-inner" aria-hidden="true"></div>
215 221 </div>
216 222 <div>
  223 + <p class="font-semibold"><a href="{{ route('admin.education.index') }}">Справочник образования</a></p>
  224 + <p class="text-xs text-gray-600 dark:text-gray-400">
  225 + Справочник образование
  226 + </p>
  227 + </div>
  228 + </div>
  229 + </td>
  230 + <td class="px-4 py-3 text-sm">
  231 + education
  232 + </td>
  233 + <td class="px-4 py-3 text-xs">
  234 + <span class="px-2 py-1 font-semibold leading-tight text-green-700 bg-green-100 rounded-full dark:bg-green-700 dark:text-green-100">
  235 + Доступно
  236 + </span>
  237 + </td>
  238 + <td class="px-4 py-3 text-sm">
  239 + октябрь 2023
  240 + </td>
  241 + </tr>
  242 +
  243 + <tr class="text-gray-700 dark:text-gray-400">
  244 + <td class="px-4 py-3">
  245 + <div class="flex items-center text-sm">
  246 + <div class="relative hidden w-8 h-8 mr-3 rounded-full md:block">
  247 + <div class="absolute inset-0 rounded-full shadow-inner" aria-hidden="true"></div>
  248 + </div>
  249 + <div>
217 250 <p class="font-semibold"><a href="{{ route('admin.categories.index') }}">Категории вакансий</a></p>
218 251 <p class="text-xs text-gray-600 dark:text-gray-400">
219 252 Справочник категории вакансий (по умолчанию: река, море, река-море)
... ... @@ -376,9 +409,15 @@
376 409 <div class="absolute inset-0 rounded-full shadow-inner" aria-hidden="true"></div>
377 410 </div>
378 411 <div>
379   - <p class="font-semibold"><a href="{{ route('admin.roles') }}">Роли пользователей</a></p>
  412 + <p class="font-semibold">
  413 + @if ($UserId == 1)
  414 + <a href="{{ route('admin.roles') }}">Роли пользователей</a>
  415 + @else
  416 + Роли пользователей
  417 + @endif
  418 + </p>
380 419 <p class="text-xs text-gray-600 dark:text-gray-400">
381   - Роли людей (запреты и доступы) в системе
  420 + Роли людей (запреты и доступы) в системе. Только для разработчика!
382 421 </p>
383 422 </div>
384 423 </div>
... ... @@ -387,8 +426,8 @@
387 426 users
388 427 </td>
389 428 <td class="px-4 py-3 text-xs">
390   - <span class="px-2 py-1 font-semibold leading-tight text-green-700 bg-green-100 rounded-full dark:bg-green-700 dark:text-green-100">
391   - Доступно
  429 + <span class="px-2 py-1 font-semibold leading-tight text-orange-700 bg-orange-100 rounded-full dark:text-white dark:bg-orange-600">
  430 + Недоступно
392 431 </span>
393 432 </td>
394 433 <td class="px-4 py-3 text-sm">
resources/views/admin/message/index.blade.php
... ... @@ -61,15 +61,27 @@
61 61 <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
62 62 @foreach($Msgs as $msg)
63 63 <tr class="text-gray-700 dark:text-gray-400"
64   - @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) style="background-color: #403998;" @endif>
  64 + @if (isset($msg->user_to->id))
  65 + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1))
  66 + style="background-color: #403998;"
  67 + @endif
  68 + @endif>
65 69 <td class="px-4 py-3">
66 70 {{$msg->id}}
67 71 </td>
68 72 <td class="px-4 py-3">
  73 + @if (isset($msg->user_from->name))
69 74 {{$msg->user_from->name}} ({{$msg->user_from->id}})
  75 + @else
  76 + Пользователь удален
  77 + @endif
70 78 </td>
71 79 <td class="px-4 py-3">
  80 + @if (isset($msg->user_to->name))
72 81 {{$msg->user_to->name}} ({{$msg->user_to->id}})
  82 + @else
  83 + Пользователь удален
  84 + @endif
73 85 </td>
74 86 <td class="px-4 py-3">
75 87 {{$msg->title}}
... ... @@ -81,9 +93,11 @@
81 93 {{ $msg->created_at }}
82 94 </td>
83 95 <td class="px-4 py-3 text-sm">
84   - @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1))
  96 + @if (isset($msg->user_to->id))
  97 + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1))
85 98 <input type="checkbox" class="checkread" value="{{$msg->id}}" name="read_{{$msg->id}}"/>
86 99 @endif
  100 + @endif
87 101 </td>
88 102 </tr>
89 103 @endforeach
resources/views/admin/message/index2.blade.php
... ... @@ -0,0 +1,174 @@
  1 +@extends('layout.admin', ['title' => 'Админка - Сообщения адмистратора'])
  2 +
  3 +@section('script')
  4 + <script>
  5 + $(document).ready(function() {
  6 + $(document).on('change', '.checkread', function () {
  7 + var this_ = $(this);
  8 + var value = this_.val();
  9 + var ajax_block = $('#ajax_block');
  10 + var bool = 0;
  11 +
  12 + if(this.checked){
  13 + bool = 1;
  14 + } else {
  15 + bool = 0;
  16 + }
  17 +
  18 + $.ajax({
  19 + type: "GET",
  20 + url: "{{ url()->full()}}",
  21 + data: "id=" + value + "&flag_new=" + bool,
  22 + success: function (data) {
  23 + console.log('Обновление таблицы сообщений администратора ');
  24 + //data = JSON.parse(data);
  25 + //console.log(data);
  26 + ajax_block.html(data);
  27 + },
  28 + headers: {
  29 + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  30 + },
  31 + error: function (data) {
  32 + console.log('Error: ' + data);
  33 + }
  34 + });
  35 + });
  36 +
  37 + });
  38 + </script>
  39 +@endsection
  40 +
  41 +@section('search')
  42 +
  43 +@endsection
  44 +
  45 +@section('content')
  46 + <div class="w-full overflow-hidden rounded-lg shadow-xs" id="ajax_block">
  47 + <div class="w-full overflow-x-auto">
  48 + <table class="w-full whitespace-no-wrap">
  49 + <thead>
  50 + <tr
  51 + class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800"
  52 + >
  53 + <th class="px-4 py-3">№</th>
  54 + <th class="px-4 py-3">От юзера</th>
  55 + <th class="px-4 py-3">К юзеру</th>
  56 + <th class="px-4 py-3">Текст</th>
  57 + <th class="px-4 py-3">Дата</th>
  58 + <th class="px-4 py-3">Прочтено</th>
  59 + </tr>
  60 + </thead>
  61 + <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
  62 + @foreach($Msgs as $msg)
  63 + <tr class="text-gray-700 dark:text-gray-400"
  64 + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) style="background-color: #403998;" @endif>
  65 + <td class="px-4 py-3">
  66 + {{$msg->id}}
  67 + </td>
  68 + <td class="px-4 py-3">
  69 + <!--if (isset($msg->user_from->name))
  70 + $msg->user_from->name ($msg->user_from->id)
  71 + else
  72 + Пользователь удален
  73 + endif-->
  74 + </td>
  75 + <td class="px-4 py-3">
  76 + <!--if (isset($msg->user_to->name))
  77 + $msg->user_to->name ($msg->user_to->id)
  78 + else
  79 + Пользователь удален
  80 + @endif-->
  81 + </td>
  82 + <td class="px-4 py-3">
  83 + {{$msg->title}}
  84 + <div class="flex items-center text-sm">
  85 + <textarea cols="7" style="width:250px;">{{ $msg->text }}</textarea>
  86 + </div>
  87 + </td>
  88 + <td class="px-4 py-3 text-sm">
  89 + {{ $msg->created_at }}
  90 + </td>
  91 + <td class="px-4 py-3 text-sm">
  92 + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1))
  93 + <input type="checkbox" class="checkread" value="{{$msg->id}}" name="read_{{$msg->id}}"/>
  94 + @endif
  95 + </td>
  96 + </tr>
  97 + @endforeach
  98 + </tbody>
  99 + </table>
  100 + </div>
  101 +
  102 + <div class="grid px-4 py-3 text-xs font-semibold tracking-wide text-gray-500 uppercase border-t dark:border-gray-700 bg-gray-50 sm:grid-cols-9 dark:text-gray-400 dark:bg-gray-800">
  103 + <?=$Msgs->appends($_GET)->links('admin.pagginate'); ?>
  104 + </div>
  105 + </div><br>
  106 +
  107 + <div class="w-full overflow-hidden rounded-lg shadow-xs" id="ajax_block2">
  108 +
  109 + <form method="POST" action="{{ route('admin.admin-messages-post') }}" enctype="multipart/form-data">
  110 + @csrf
  111 + <div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
  112 + <h3 class="text-gray-700 dark:text-gray-400">Отправка сообщения</h3>
  113 + <hr>
  114 + <label for="ad_employer_id" class="block text-sm">
  115 + <input type="hidden" name="user_id" id="user_id" value="{{ $id_admin }}"/>
  116 +
  117 + <span class="text-gray-700 dark:text-gray-400">Кому:</span>
  118 +
  119 + <select name="to_user_id" id="to_user_id" class="block change_js mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray">
  120 + @foreach($users as $user)
  121 + <option value="{{ $user->id }}">{{ $user->name }} ({{ $user->id }})</option>
  122 + @endforeach
  123 + </select>
  124 + </label><br>
  125 +
  126 + <label class="block text-sm">
  127 + <span class="text-gray-700 dark:text-gray-400">Заголовок</span>
  128 + <input name="title" id="title"
  129 + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input"
  130 + placeholder="Заголовок" value="{{ old('title') ?? '' }}"
  131 + />
  132 + @error('title')
  133 + <span class="text-xs text-red-600 dark:text-red-400">
  134 + {{ $message }}
  135 + </span>
  136 + @enderror
  137 + </label><br>
  138 +
  139 + <label class="block text-sm">
  140 + <span class="text-gray-700 dark:text-gray-400">Текст</span>
  141 + <textarea class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-textarea focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray" name="text" placeholder="Текст" required
  142 + rows="4">{{ old('text') ?? '' }}</textarea>
  143 + @error('text')
  144 + <span class="text-xs text-red-600 dark:text-red-400">
  145 + {{ $message }}
  146 + </span>
  147 + @enderror
  148 + </label><br>
  149 +
  150 +
  151 + <label class="block text-sm">
  152 + <span class="text-gray-700 dark:text-gray-400">Файл</span>
  153 + <input type="file" class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700
  154 + focus:border-purple-400 focus:outline-none focus:shadow-outline-purple
  155 + dark:text-gray-300 dark:focus:shadow-outline-gray form-input"
  156 + id="file" name="file">
  157 + @error('file')
  158 + <span class="text-xs text-red-600 dark:text-red-400">
  159 + {{ $message }}
  160 + </span>
  161 + @enderror
  162 + </label><br>
  163 +
  164 + <div class="flex flex-col flex-wrap mb-4 space-y-4 md:flex-row md:items-end md:space-x-4">
  165 + <div>
  166 + <button type="submit" class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple">
  167 + Отправить
  168 + </button>
  169 + </div>
  170 + </div>
  171 + </div>
  172 + </form>
  173 + </div>
  174 +@endsection
resources/views/admin/message/index_ajax.blade.php
... ... @@ -15,15 +15,26 @@
15 15 <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
16 16 @foreach($Msgs as $msg)
17 17 <tr class="text-gray-700 dark:text-gray-400"
18   - @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) style="background-color: #403998;" @endif>
  18 + @if (isset($msg->user_to->id))
  19 + @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1)) style="background-color: #403998;"
  20 + @endif
  21 + @endif>
19 22 <td class="px-4 py-3">
20 23 {{$msg->id}}
21 24 </td>
22 25 <td class="px-4 py-3">
  26 + @if ((isset($msg->user_from->name)) && (!empty($msg->user_from->name)))
23 27 {{$msg->user_from->name}} ({{$msg->user_from->id}})
  28 + @else
  29 + Пользователь удален
  30 + @endif
24 31 </td>
25 32 <td class="px-4 py-3">
  33 + @if ((isset($msg->user_to->name)) && (!empty($msg->user_to->name)))
26 34 {{$msg->user_to->name}} ({{$msg->user_to->id}})
  35 + @else
  36 + Пользователь удален
  37 + @endif
27 38 </td>
28 39 <td class="px-4 py-3">
29 40 {{$msg->title}}
... ... @@ -35,9 +46,11 @@
35 46 {{ $msg->created_at }}
36 47 </td>
37 48 <td class="px-4 py-3 text-sm">
  49 + @if (isset($msg->user_to->id))
38 50 @if (($msg->user_to->id == $id_admin) && ($msg->flag_new == 1))
39 51 <input type="checkbox" class="checkread" value="{{$msg->id}}" name="read_{{$msg->id}}"/>
40 52 @endif
  53 + @endif
41 54 </td>
42 55 </tr>
43 56 @endforeach
resources/views/admin/messages.blade.php
... ... @@ -55,10 +55,18 @@
55 55 {{$msg->id}}
56 56 </td>
57 57 <td class="px-4 py-3">
  58 + @if (isset($msg->user_from->id))
58 59 {{$msg->user_from->name}} ({{$msg->user_from->id}})
  60 + @else
  61 + Пользователь удален
  62 + @endif
59 63 </td>
60 64 <td class="px-4 py-3">
  65 + @if (isset($msg->user_to->id))
61 66 {{$msg->user_to->name}} ({{$msg->user_to->id}})
  67 + @else
  68 + Пользователь удален
  69 + @endif
62 70 </td>
63 71 <td class="px-4 py-3">
64 72 {{$msg->title}}
resources/views/layout/admin.blade.php
... ... @@ -61,6 +61,7 @@
61 61 </li>
62 62 </ul>
63 63 <ul>
  64 + @if ($UserId == 1)
64 65 <li class="relative px-6 py-3">
65 66 <a
66 67 class="inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
... ... @@ -83,6 +84,7 @@
83 84 <span class="ml-4">Пользователи</span>
84 85 </a>
85 86 </li>
  87 + @endif
86 88 <li class="relative px-6 py-3">
87 89 <a
88 90 class="inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
... ... @@ -168,7 +170,7 @@
168 170 >
169 171 <path d="M4 6h16M4 10h16M4 14h16M4 18h16"></path>
170 172 </svg>
171   - <span class="ml-4">Сообщения</span>
  173 + <span class="ml-4">Сообщения все</span>
172 174 </a>
173 175 </li>
174 176 <li class="relative px-6 py-3">
... ... @@ -193,6 +195,7 @@
193 195 <span class="ml-4">Группы пользователей</span>
194 196 </a>
195 197 </li>
  198 + @if ($UserId == 1)
196 199 <li class="relative px-6 py-3">
197 200 <a class="inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
198 201 href="{{ route('admin.roles') }}">
... ... @@ -213,6 +216,7 @@
213 216 <span class="ml-4">Роли пользователей</span>
214 217 </a>
215 218 </li>
  219 + @endif
216 220 <li class="relative px-6 py-3">
217 221 <a
218 222 class="inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
... ... @@ -312,6 +316,9 @@
312 316 <a class="w-full" href="{{ route('admin.category-emp.index') }}">Категории работодателей</a>
313 317 </li>
314 318 <li class="px-2 py-1 transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200">
  319 + <a class="w-full" href="{{ route('admin.education.index') }}">Образование</a>
  320 + </li>
  321 + <li class="px-2 py-1 transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200">
315 322 <a class="w-full" href="{{ route('admin.infobloks.index') }}">Блоки-Дипломы</a>
316 323 </li>
317 324  
... ... @@ -462,6 +469,7 @@
462 469 </li>
463 470 </ul>
464 471 <ul>
  472 + @if ($UserId == 1)
465 473 <li class="relative px-6 py-3">
466 474 <a class="inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
467 475 href="{{ route('admin.users') }}">
... ... @@ -482,6 +490,7 @@
482 490 <span class="ml-4">Пользователи</span>
483 491 </a>
484 492 </li>
  493 + @endif
485 494 <li class="relative px-6 py-3">
486 495 <a
487 496 class="inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
... ... @@ -566,7 +575,7 @@
566 575 >
567 576 <path d="M4 6h16M4 10h16M4 14h16M4 18h16"></path>
568 577 </svg>
569   - <span class="ml-4">Сообщения</span>
  578 + <span class="ml-4">Сообщения все</span>
570 579 </a>
571 580 </li>
572 581 <li class="relative px-6 py-3">
... ... @@ -589,6 +598,7 @@
589 598 <span class="ml-4">Группы пользователей</span>
590 599 </a>
591 600 </li>
  601 + @if ($UserId == 1)
592 602 <li class="relative px-6 py-3">
593 603 <a class="inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
594 604 href="{{ route('admin.roles') }}">
... ... @@ -609,6 +619,7 @@
609 619 <span class="ml-4">Роли пользователей</span>
610 620 </a>
611 621 </li>
  622 + @endif
612 623 <li class="relative px-6 py-3">
613 624 <a
614 625 class="inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
... ... @@ -708,6 +719,9 @@
708 719 <a class="w-full" href="{{ route('admin.category-emp.index') }}">Категории работодателей</a>
709 720 </li>
710 721 <li class="px-2 py-1 transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200">
  722 + <a class="w-full" href="{{ route('admin.education.index') }}">Образование</a>
  723 + </li>
  724 + <li class="px-2 py-1 transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200">
711 725 <a class="w-full" href="{{ route('admin.infobloks.index') }}">Блоки-Дипломы</a>
712 726 </li>
713 727  
... ... @@ -3,6 +3,7 @@
3 3 use App\Http\Controllers\Admin\AdminController;
4 4 use App\Http\Controllers\Admin\CategoryController;
5 5 use App\Http\Controllers\Admin\CategoryEmpController;
  6 +use App\Http\Controllers\Admin\EducationController;
6 7 use App\Http\Controllers\Admin\EmployersController;
7 8 use App\Http\Controllers\Admin\InfoBloksController;
8 9 use App\Http\Controllers\Admin\JobTitlesController;
... ... @@ -159,6 +160,8 @@ Route::group([
159 160 Route::get('employer-profile/{employer}', [EmployersController::class, 'form_update_employer'])->name('employer-profile');
160 161 // кабинет профиль работодатель - сохранение формы
161 162 Route::post('employer-profile/{employer}', [EmployersController::class, 'update_employer'])->name('update-employer-profile');
  163 + // кабинет удаление профиль работодателя и юзера
  164 + Route::delete('employer-profile/delete/{employer}/{user}', [EmployersController::class, 'delete_employer'])->name('delete-employer');
162 165  
163 166 // кабинет профиль работник - форма
164 167 Route::get('worker-profile/{worker}', [WorkersController::class, 'form_edit_worker'])->name('worker-profile-edit');
... ... @@ -196,6 +199,9 @@ Route::group([
196 199 // CRUD-операции над справочником Категории для работодателей
197 200 Route::resource('category-emp', CategoryEmpController::class, ['except' => ['show']]);
198 201  
  202 + // CRUD-операции над справочником Образование
  203 + Route::resource('education', EducationController::class, ['except' => ['show']]);
  204 +
199 205 //Route::get('job-titles', [AdminController::class, 'index'])->name('job-titles');
200 206 /*
201 207 * кабинет - CRUD-операции по справочнику должности