From 29350503f1ddb5f83f6fbcb1e3fdc8cd8dcb45b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=20=D0=9B=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Thu, 7 Sep 2023 21:02:55 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D0?= =?UTF-8?q?=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=BC=D0=BE=D0=B4=D0?= =?UTF-8?q?=B5=D0=BB=D0=B5=D0=B9,=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D1=8B=20=D0?= =?UTF-8?q?=B8=20=D0=BA=D0=B0=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D0=B8=20=D1?= =?UTF-8?q?=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BE=D1=87=D0=BD=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/CategoryController.php | 8 +- app/Http/Controllers/Admin/EmployersController.php | 17 +- app/Http/Controllers/Admin/GroupsController.php | 25 +- app/Http/Controllers/Admin/UsersController.php | 16 +- app/Models/Ad_employer.php | 17 ++ app/Models/Answer.php | 28 +++ app/Models/Category.php | 5 + app/Models/Employer.php | 9 + app/Models/Group_user.php | 13 ++ app/Models/Group_works.php | 35 +++ app/Models/Job_title.php | 9 + app/Models/User.php | 20 +- app/Models/Worker.php | 7 + .../2023_09_07_134401_alter_group_users_table.php | 32 +++ resources/views/admin/answers/index.blade.php | 130 +++++++++++ resources/views/admin/answers/index_ajax.blade.php | 49 ++++ resources/views/admin/category/index.blade.php | 4 +- resources/views/admin/groups/form.blade.php | 34 ++- resources/views/admin/groups/index.blade.php | 9 +- resources/views/admin/static/index.blade.php | 65 ++++++ resources/views/admin/users/roles/index.blade.php | 238 ++++++++++++++++++++ .../views/admin/users/roles/index_ajax.blade.php | 59 +++++ routes/web.php | 2 + 23 files changed, 812 insertions(+), 19 deletions(-) create mode 100644 app/Models/Group_works.php create mode 100644 database/migrations/2023_09_07_134401_alter_group_users_table.php create mode 100644 resources/views/admin/answers/index.blade.php create mode 100644 resources/views/admin/answers/index_ajax.blade.php create mode 100644 resources/views/admin/users/roles/index.blade.php create mode 100644 resources/views/admin/users/roles/index_ajax.blade.php diff --git a/app/Http/Controllers/Admin/CategoryController.php b/app/Http/Controllers/Admin/CategoryController.php index c98d2e6..8c7d363 100644 --- a/app/Http/Controllers/Admin/CategoryController.php +++ b/app/Http/Controllers/Admin/CategoryController.php @@ -18,7 +18,7 @@ class CategoryController extends Controller */ public function index() { - $category = Category::query()->paginate(15); + $category = Category::query()->active()->paginate(15); return view('admin.category.index', compact('category')); } @@ -87,9 +87,11 @@ class CategoryController extends Controller */ public function destroy(Category $category) { - if (Auth::user()->id == 1) { + /*if (Auth::user()->id == 1) { $category->delete(); - } + } else {*/ + $category->update(['is_remove' => 1]); + //} return redirect()->route('admin.categories.index'); } } diff --git a/app/Http/Controllers/Admin/EmployersController.php b/app/Http/Controllers/Admin/EmployersController.php index edb589f..a3dfb36 100644 --- a/app/Http/Controllers/Admin/EmployersController.php +++ b/app/Http/Controllers/Admin/EmployersController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Answer; use App\Models\Employer; use App\Models\User; use Illuminate\Http\Request; @@ -89,8 +90,20 @@ class EmployersController extends Controller } // кабинет - отзывы о работодателе для модерации - public function answers() { - return; + public function answers(Request $request) { + if ($request->ajax()) { + $user = Answer::find($request->id); + $request->offsetUnset('id'); + $user->update($request->all()); + } + + $answers = Answer::query()->orderByDesc('id')->paginate(15); + + if ($request->ajax()) { + return view('admin.answers.index_ajax', compact('answers')); + } else { + return view('admin.answers.index', compact('answers')); + } } // кабинет - статистика вакансий работодателя diff --git a/app/Http/Controllers/Admin/GroupsController.php b/app/Http/Controllers/Admin/GroupsController.php index 22f1a5f..e3c17ae 100644 --- a/app/Http/Controllers/Admin/GroupsController.php +++ b/app/Http/Controllers/Admin/GroupsController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Group_user; +use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; @@ -12,14 +13,15 @@ class GroupsController extends Controller { // индексная страница public function index() { - $groups = Group_user::query()->paginate(15); + $groups = Group_user::query()->active()->paginate(15); return view('admin.groups.index', compact('groups')); } // форма добавления группы public function add() { $editor = Auth::user()->id; - return view('admin.groups.add', compact('editor')); + $users = User::query()->get(); + return view('admin.groups.add', compact('editor', 'users')); } // форма сохранения добавленной группы @@ -46,11 +48,15 @@ class GroupsController extends Controller // форма редактирования группы public function edit(Group_user $group, Request $request) { $editor = Auth::user()->id; - return view('admin.groups.edit', compact('editor', 'group')); + $users = User::query()->get(); + return view('admin.groups.edit', compact('editor', 'group', 'users')); } // форма сохранения редактированной группы public function update(Group_user $group, Request $request) { + + $params = $request->all(); + unset($params['usergroup']); $rules = [ 'name_group' => 'required|min:3', ]; @@ -64,9 +70,22 @@ class GroupsController extends Controller ->withErrors($validator); } else { $group->update($request->all()); + $group->ingroup()->sync($request->usergroup); + /*if ($request->usergroup->count()) { + foreach ($request->usergroup as $us) { + Group_works + } + }*/ + return redirect()->route('admin.groups') ->with('success', 'Данные были успешно сохранены'); } return redirect()->route('admin.groups'); } + + public function destroy(Group_user $group) { + $group->update(['is_remove' => 1]); + + return redirect()->route('admin.groups'); + } } diff --git a/app/Http/Controllers/Admin/UsersController.php b/app/Http/Controllers/Admin/UsersController.php index 14e0782..57bbbd3 100644 --- a/app/Http/Controllers/Admin/UsersController.php +++ b/app/Http/Controllers/Admin/UsersController.php @@ -27,7 +27,19 @@ class UsersController extends Controller } } - public function roles() { - return; + public function roles(Request $request) { + if ($request->ajax()) { + $user = User::find($request->id); + $request->offsetUnset('id'); + $user->update($request->all()); + } + + $users = User::query()->paginate(15); + + if ($request->ajax()) { + return view('admin.users.roles.index_ajax', compact('users')); + } else { + return view('admin.users.roles.index', compact('users')); + } } } diff --git a/app/Models/Ad_employer.php b/app/Models/Ad_employer.php index ca17d8b..2bd9d4d 100644 --- a/app/Models/Ad_employer.php +++ b/app/Models/Ad_employer.php @@ -9,6 +9,19 @@ class Ad_employer extends Model { use HasFactory; + protected $fillable = [ + 'name', + 'telephone', + 'email', + 'salary', + 'category_id', + 'text', + 'employer_id', + 'city', + 'sort', + 'is_remove', + 'active_is', + ]; /* * Связь таблицы employers с таблицей ad_employers многие-к-одному @@ -32,4 +45,8 @@ class Ad_employer extends Model public function response() { return $this->hasMany(ad_response::class); } + + public function scopeActive($query) { + return $query->where('is_remove', '=', '0'); + } } diff --git a/app/Models/Answer.php b/app/Models/Answer.php index c2e96b1..d48fd42 100644 --- a/app/Models/Answer.php +++ b/app/Models/Answer.php @@ -8,4 +8,32 @@ use Illuminate\Database\Eloquent\Model; class Answer extends Model { use HasFactory; + + protected $fillable = [ + 'employer_id', + 'user_id', + 'plus', + 'minus', + 'rate', + 'title', + 'text', + 'is_moderate', + ]; + + /* + * Связь таблицы employers с таблицей answers + многие-к-одному + */ + public function employer() { + return $this->belongsTo(Employer::class, 'employer_id'); + } + + /* + * Связь таблицы users с таблицей answers + многие-к-одному + */ + public function user() { + return $this->belongsTo(User::class, 'user_id'); + } + } diff --git a/app/Models/Category.php b/app/Models/Category.php index 846941f..5434c3e 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -11,5 +11,10 @@ class Category extends Model protected $fillable = [ 'name', + 'is_remove' ]; + + public function scopeActive($query) { + return $query->where('is_remove', '=', '0'); + } } diff --git a/app/Models/Employer.php b/app/Models/Employer.php index aae29aa..78cc299 100644 --- a/app/Models/Employer.php +++ b/app/Models/Employer.php @@ -21,6 +21,12 @@ class Employer extends Model 'address', 'map', 'site', + 'coord', + 'plus', + 'is_remove', + 'oficial_status', + 'social_is', + 'sending_is', ]; /* @@ -37,5 +43,8 @@ class Employer extends Model return $this->hasMany(Ad_employer::class); } + public function scopeActive($query) { + return $query->where('is_remove', '=', '0'); + } } diff --git a/app/Models/Group_user.php b/app/Models/Group_user.php index 50bf2c4..4a135c9 100644 --- a/app/Models/Group_user.php +++ b/app/Models/Group_user.php @@ -12,6 +12,7 @@ class Group_user extends Model protected $fillable = [ 'name_group', 'user_id', + 'is_remove', ]; /* @@ -30,4 +31,16 @@ class Group_user extends Model return $this->belongsToMany(User::class, 'group_works'); } + /* + * Связь модели Группы (Group_users) с моделью Группы пользователей (Group_works) + один-ко-многим + */ + public function peoples() { + return $this->hasMany(Group_works::class); + } + + public function scopeActive($query) { + return $query->where('is_remove', '=', '0'); + } + } diff --git a/app/Models/Group_works.php b/app/Models/Group_works.php new file mode 100644 index 0000000..a718240 --- /dev/null +++ b/app/Models/Group_works.php @@ -0,0 +1,35 @@ +belongsTo(User::class, 'user_id'); + } + + /* + * Связь Модели Группы (Group_user) с Модели Юзеры (User) + многие-к-одному + */ + public function group() { + return $this->belongsTo(Group_user::class, 'group_user_id'); + } + +} diff --git a/app/Models/Job_title.php b/app/Models/Job_title.php index a21dc75..ecf01fb 100644 --- a/app/Models/Job_title.php +++ b/app/Models/Job_title.php @@ -9,10 +9,19 @@ class Job_title extends Model { use HasFactory; + protected $fillable = [ + 'name', + 'is_remove', + 'parent_id', + ]; /* * Связь модели Вакансии (Ad_employer) с моделью Должности (Job_title) */ public function Ads() { return $this->belongsToMany(Ad_employer::class, 'ad_jobs'); } + + public function scopeActive($query) { + return $query->where('is_remove', '=', '0'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 6d5de93..d12dbf4 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -71,11 +71,12 @@ class User extends Authenticatable } /* - * Связь Пользователей системы с группами юзеров + * Связь Модели Пользователей(Users) с Группами (Group_users) * users - group_users - */ - public function groups() { - return $this->hasMany(Group_user::class); + многие-ко-многим + */ + public function ingroup() { + return $this->belongsToMany(Group_user::class, 'group_works'); } /* @@ -94,5 +95,16 @@ class User extends Authenticatable return $this->hasMany(Static_worker::class); } + /* + * Связь модели Юзеры (users) с моделью Группы пользователей (Group_works) + один-ко-многим + */ + public function peoples() { + return $this->hasMany(Group_works::class); + } + + public function scopeActive($query) { + return $query->where('is_remove', '=', '0'); + } } diff --git a/app/Models/Worker.php b/app/Models/Worker.php index 564e122..d5ab505 100644 --- a/app/Models/Worker.php +++ b/app/Models/Worker.php @@ -39,6 +39,9 @@ class Worker extends Model 'text', 'address', 'city', + 'coord', + 'file', + 'is_remove', ]; /* @@ -47,4 +50,8 @@ class Worker extends Model public function users() { return $this->belongsTo(User::class, 'user_id'); } + + public function scopeActive($query) { + return $query->where('is_remove', '=', '0'); + } } diff --git a/database/migrations/2023_09_07_134401_alter_group_users_table.php b/database/migrations/2023_09_07_134401_alter_group_users_table.php new file mode 100644 index 0000000..b651264 --- /dev/null +++ b/database/migrations/2023_09_07_134401_alter_group_users_table.php @@ -0,0 +1,32 @@ +boolean('is_remove')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('group_users', function (Blueprint $table) { + $table->dropColumn('is_remove'); + }); + } +}; diff --git a/resources/views/admin/answers/index.blade.php b/resources/views/admin/answers/index.blade.php new file mode 100644 index 0000000..37394f2 --- /dev/null +++ b/resources/views/admin/answers/index.blade.php @@ -0,0 +1,130 @@ +@extends('layout.admin', ['title' => 'Админка - Отзывы о работодателях']) + +@section('script') + +@endsection + +@section('search') + +@endsection + +@section('content') + +
+
+ + + + + + + + + + + + + @foreach($answers as $answer) + + + + + + + + + @endforeach + +
Название компанииКомментаторЗаголовок/ТекстДата комментаРазрешить
+ {{$answer->id}} + + {{$answer->employer->name_company}} + + {{$answer->user->name}} + + +

{{$answer->title}}

+ + +
+ {{ $answer->created_at }} + + is_moderate) ? "checked" : "" }}/> +
+
+ +
+ appends($_GET)->links('admin.pagginate'); ?> +
+
+@endsection diff --git a/resources/views/admin/answers/index_ajax.blade.php b/resources/views/admin/answers/index_ajax.blade.php new file mode 100644 index 0000000..eb56446 --- /dev/null +++ b/resources/views/admin/answers/index_ajax.blade.php @@ -0,0 +1,49 @@ +
+ + + + + + + + + + + + + @foreach($answers as $answer) + + + + + + + + + @endforeach + +
Название компанииКомментаторЗаголовок/ТекстДата комментаРазрешить
+ {{$answer->id}} + + {{$answer->employer->name_company}} + + {{$answer->user->name}} + + +

{{$answer->title}}

+ + +
+ {{ $answer->created_at }} + + is_moderate) ? "checked" : "" }}/> +
+
+ +
+ appends($_GET)->links('admin.pagginate'); ?> +
diff --git a/resources/views/admin/category/index.blade.php b/resources/views/admin/category/index.blade.php index 22ae1cc..b5fc50f 100644 --- a/resources/views/admin/category/index.blade.php +++ b/resources/views/admin/category/index.blade.php @@ -99,12 +99,12 @@ {{$cat->created_at}} - +
Изменить | @csrf @method('DELETE') - +
diff --git a/resources/views/admin/groups/form.blade.php b/resources/views/admin/groups/form.blade.php index 43a4e12..4c7f621 100644 --- a/resources/views/admin/groups/form.blade.php +++ b/resources/views/admin/groups/form.blade.php @@ -11,7 +11,6 @@ @enderror
-
@@ -21,5 +20,38 @@
+ + + + + + + + + + + + @foreach($users as $user) + + + + + + @endforeach + +
Имя пользователяДобавленные в группу
+ {{$user->id}} + + {{$user->name}} + + groups->group_user_id == $group->id) {?>checked/> +
ingroup->id);?>
+
+ + diff --git a/resources/views/admin/groups/index.blade.php b/resources/views/admin/groups/index.blade.php index 99ba0a0..a824bee 100644 --- a/resources/views/admin/groups/index.blade.php +++ b/resources/views/admin/groups/index.blade.php @@ -102,8 +102,13 @@ {{ $group->created_at }} - - Изменить + +
+ Изменить | + @csrf + @method('DELETE') + +
@endforeach diff --git a/resources/views/admin/static/index.blade.php b/resources/views/admin/static/index.blade.php index e69de29..84a1779 100644 --- a/resources/views/admin/static/index.blade.php +++ b/resources/views/admin/static/index.blade.php @@ -0,0 +1,65 @@ +@extends('layout.admin', ['title' => 'Админка - Страница статистики']) + +@section('content') + + +
+
+ + + + + + + + + + + + + + + + + + +
НазваниеСсылка
+
+ +
+

Статистика пользователей

+

+ Информация о просмотрах и сообщениях пользователей разбитая по месяцам +

+
+
+
+ Ссылка +
+
+ +
+

Статистика вакансий

+

+ Информация о просмотрах и отликах о вакансиях (по месяцам) +

+
+
+
+ Ссылка +
+
+
+@endsection diff --git a/resources/views/admin/users/roles/index.blade.php b/resources/views/admin/users/roles/index.blade.php new file mode 100644 index 0000000..764135d --- /dev/null +++ b/resources/views/admin/users/roles/index.blade.php @@ -0,0 +1,238 @@ +@extends('layout.admin', ['title' => 'Роли пользователей']) + +@section('script') + +@endsection + +@section('search') +
+ +
+
+
+
+ +
+
+@endsection + +@section('content') +
+
+ + + + + + + + + + + + + + + @foreach($users as $user) + + + + + + + + + + + + + + + @endforeach + +
ИмяEmail/логинПросмотр резюмеОтправка сообщенийПубликация вакансийАдмин
+ {{$user->id}} + + {{ $user->name }} + + {{ $user->email }} + + is_lookin) ? "checked" : "" }}/> + + is_message) ? "checked" : "" }}/> + + is_public) ? "checked" : "" }}/> + + @if ($user->id > 1) + admin) ? "checked" : "" }}/> + @endif +
+
+ +
+ appends($_GET)->links('admin.pagginate'); ?> + links('admin.pagginate'); ?> +
+ + + +
+ + appends($_GET)->links('catalogs.paginate'); ?> + + +@endsection diff --git a/resources/views/admin/users/roles/index_ajax.blade.php b/resources/views/admin/users/roles/index_ajax.blade.php new file mode 100644 index 0000000..3f682f8 --- /dev/null +++ b/resources/views/admin/users/roles/index_ajax.blade.php @@ -0,0 +1,59 @@ +
+ + + + + + + + + + + + + + + @foreach($users as $user) + + + + + + + + + + + + + + + @endforeach + +
ИмяEmail/логинПросмотр резюмеОтправка сообщенийПубликация вакансийАдмин
+ {{$user->id}} + + {{ $user->name }} + + {{ $user->email }} + + is_lookin) ? "checked" : "" }}/> + + is_message) ? "checked" : "" }}/> + + is_public) ? "checked" : "" }}/> + + @if ($user->id > 1) + admin) ? "checked" : "" }}/> + @endif +
+
+ +
+ appends($_GET)->links('admin.pagginate'); ?> + links('admin.pagginate'); ?> +
diff --git a/routes/web.php b/routes/web.php index a5eabf8..6ae11c2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -149,6 +149,8 @@ Route::group([ Route::get('groups/edit/{group}', [GroupsController::class, 'edit'])->name('edit-group'); // кабинет - сохранение редактированной формы группы пользователей Route::post('groups/edit/{group}', [GroupsController::class, 'update'])->name('update-group'); + // кабинет - удаление группы пользователей + Route::delete('groups/delete/{group}', [GroupsController::class, 'destroy'])->name('delete-group'); // кабинет - список админов Route::get('group-admin', [AdminController::class, 'index'])->name('group-admin'); -- 1.7.10.4