diff --git a/app/Http/Controllers/Admin/GroupsController.php b/app/Http/Controllers/Admin/GroupsController.php new file mode 100644 index 0000000..22f1a5f --- /dev/null +++ b/app/Http/Controllers/Admin/GroupsController.php @@ -0,0 +1,72 @@ +paginate(15); + return view('admin.groups.index', compact('groups')); + } + + // форма добавления группы + public function add() { + $editor = Auth::user()->id; + return view('admin.groups.add', compact('editor')); + } + + // форма сохранения добавленной группы + public function store(Request $request) { + $rules = [ + 'name_group' => 'required|min:3', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.add-group') + ->withErrors($validator); + } else { + Group_user::create($request->all()); + return redirect()->route('admin.groups') + ->with('success', 'Данные были успешно сохранены'); + } + return redirect()->route('admin.groups'); + } + + // форма редактирования группы + public function edit(Group_user $group, Request $request) { + $editor = Auth::user()->id; + return view('admin.groups.edit', compact('editor', 'group')); + } + + // форма сохранения редактированной группы + public function update(Group_user $group, Request $request) { + $rules = [ + 'name_group' => 'required|min:3', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.edit-group', ['group' => $group->id]) + ->withErrors($validator); + } else { + $group->update($request->all()); + return redirect()->route('admin.groups') + ->with('success', 'Данные были успешно сохранены'); + } + return redirect()->route('admin.groups'); + } +} diff --git a/app/Http/Controllers/Admin/MsgAnswersController.php b/app/Http/Controllers/Admin/MsgAnswersController.php new file mode 100644 index 0000000..89dedef --- /dev/null +++ b/app/Http/Controllers/Admin/MsgAnswersController.php @@ -0,0 +1,16 @@ +orderByDesc('created_at')->paginate(25); + + return view('admin.messages', compact('Msgs')); + } +} diff --git a/app/Models/Ad_employer.php b/app/Models/Ad_employer.php index 8a0025a..ca17d8b 100644 --- a/app/Models/Ad_employer.php +++ b/app/Models/Ad_employer.php @@ -11,8 +11,25 @@ class Ad_employer extends Model /* * Связь таблицы employers с таблицей ad_employers + многие-к-одному */ public function employer() { return $this->belongsTo(Employer::class, 'employer_id'); } + + /* + * Связь модели Вакансии (Ad_employer) с моделью Должности (Job_title) + многие-ко-многим + */ + public function jobs() { + return $this->belongsToMany(Job_title::class, 'ad_jobs'); + } + + /* + * Связь модели Вакансия (Ad_employers) с моделью Отклик на Вакансию (Ad_response) + один-ко-многим + */ + public function response() { + return $this->hasMany(ad_response::class); + } } diff --git a/app/Models/Employer.php b/app/Models/Employer.php index f3d74d9..aae29aa 100644 --- a/app/Models/Employer.php +++ b/app/Models/Employer.php @@ -30,4 +30,12 @@ class Employer extends Model return $this->belongsTo(User::class, 'user_id'); } + /* + * Связь Работодателя с вакансиями + */ + public function ads() { + return $this->hasMany(Ad_employer::class); + } + + } diff --git a/app/Models/Group_user.php b/app/Models/Group_user.php index 46f384b..50bf2c4 100644 --- a/app/Models/Group_user.php +++ b/app/Models/Group_user.php @@ -8,4 +8,26 @@ use Illuminate\Database\Eloquent\Model; class Group_user extends Model { use HasFactory; + + protected $fillable = [ + 'name_group', + 'user_id', + ]; + + /* + * Связь Модели Группы (Group_user) с Модели Юзеры (User) + многие-к-одному + */ + public function user() { + return $this->belongsTo(User::class, 'user_id'); + } + + /* + * Связь модели Группы (Group_user) с Моделью Юзеры (User) - участники группы + многие-ко-многим + */ + public function ingroup() { + return $this->belongsToMany(User::class, 'group_works'); + } + } diff --git a/app/Models/Job_title.php b/app/Models/Job_title.php index 12074da..a21dc75 100644 --- a/app/Models/Job_title.php +++ b/app/Models/Job_title.php @@ -8,4 +8,11 @@ use Illuminate\Database\Eloquent\Model; class Job_title extends Model { use HasFactory; + + /* + * Связь модели Вакансии (Ad_employer) с моделью Должности (Job_title) + */ + public function Ads() { + return $this->belongsToMany(Ad_employer::class, 'ad_jobs'); + } } diff --git a/app/Models/Message.php b/app/Models/Message.php index b9f7393..fcb867d 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -8,4 +8,25 @@ use Illuminate\Database\Eloquent\Model; class Message extends Model { use HasFactory; + + /* + * Связь таблицы Message с таблицей User (Отправитель) + */ + public function user_from() { + return $this->belongsTo(User::class, 'user_id'); + } + + /* + * Связь таблицы Message с таблицей User (Получатель) + */ + public function user_to() { + return $this->belongsTo(User::class, 'to_user_id'); + } + + /* + * Связь модели Сообщения (Message) с моделью Отклик на Вакансию (Ad_response) + */ + public function response() { + return $this->hasMany(ad_response::class); + } } diff --git a/app/Models/ad_response.php b/app/Models/ad_response.php index 7b014e2..22bb18e 100644 --- a/app/Models/ad_response.php +++ b/app/Models/ad_response.php @@ -8,4 +8,26 @@ use Illuminate\Database\Eloquent\Model; class ad_response extends Model { use HasFactory; + + /* + * Связь таблицы Отклик на вакансию (ad_response) с таблицей Вакансия (ad_employer) + */ + public function ad_employer() { + return $this->belongsTo(Ad_employer::class, 'ad_employer_id'); + } + + /* + * Связь таблицы Отклик на вакансию (ad_response) с таблицей Должность (job_title) + */ + public function job_title() { + return $this->belongsTo(Job_title::class, 'job_title_id'); + } + + /* + * Связь таблицы Отклик на вакансию (ad_response) с таблицей Сообщение (messages) + */ + public function message() { + return $this->belongsTo(Message::class, 'message_id'); + } + } diff --git a/composer.json b/composer.json index fbf6301..5593579 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "laravel/framework": "^9.19", "laravel/sanctum": "^3.0", "laravel/tinker": "^2.7", - "laravel/ui": "^4.2" + "laravel/ui": "^4.2", + "ext-http": "*" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/database/migrations/2023_05_16_092746_alter_ad_jobs_table.php b/database/migrations/2023_05_16_092746_alter_ad_jobs_table.php index 11167d5..83389dd 100644 --- a/database/migrations/2023_05_16_092746_alter_ad_jobs_table.php +++ b/database/migrations/2023_05_16_092746_alter_ad_jobs_table.php @@ -15,8 +15,6 @@ return new class extends Migration { Schema::create('ad_jobs', function (Blueprint $table) { $table->id(); - $table->bigInteger('ad_employer_id')->nullable(false); - $table->bigInteger('job_title_id')->nullable(false); $table->timestamps(); }); } diff --git a/database/migrations/2023_09_01_135734_create_dop_info_table.php b/database/migrations/2023_09_01_135734_create_dop_info_table.php index 5e7ebf9..ebfe875 100644 --- a/database/migrations/2023_09_01_135734_create_dop_info_table.php +++ b/database/migrations/2023_09_01_135734_create_dop_info_table.php @@ -15,8 +15,6 @@ return new class extends Migration { Schema::create('dop_info', function (Blueprint $table) { $table->id(); - $table->bigInteger('worker_id')->nullable(false); - $table->bigInteger('infoblok_id')->nullable(false); $table->text('text')->nullable(); $table->timestamps(); }); diff --git a/database/migrations/2023_09_06_090200_alter_dop_info_table.php b/database/migrations/2023_09_06_090200_alter_dop_info_table.php new file mode 100644 index 0000000..b2d366b --- /dev/null +++ b/database/migrations/2023_09_06_090200_alter_dop_info_table.php @@ -0,0 +1,46 @@ +unsignedBigInteger('infoblok_id')->nullable(); + //внешний ключ, ссылается на поле id таблицы infobloks + $table->foreign('infoblok_id', 'key_infoblok_id') + ->references('id') + ->on('infobloks') + ->onDelete('cascade'); + + $table->unsignedBigInteger('worker_id')->nullable(); + //внешний ключ, ссылается на поле id таблицы workers + $table->foreign('worker_id', 'key_worker_id') + ->references('id') + ->on('workers') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('dop_info', function (Blueprint $table) { + $table->dropIndex(['key_infoblok_id']); + $table->dropIndex(['key_worker_id']); + }); + } +}; diff --git a/database/migrations/2023_09_06_090312_alter_ad_jobs_table.php b/database/migrations/2023_09_06_090312_alter_ad_jobs_table.php new file mode 100644 index 0000000..ef15a98 --- /dev/null +++ b/database/migrations/2023_09_06_090312_alter_ad_jobs_table.php @@ -0,0 +1,47 @@ +unsignedBigInteger('ad_employer_id')->nullable(); + //внешний ключ, ссылается на поле id таблицы ad_employers + $table->foreign('ad_employer_id', 'key_ad_employer_id') + ->references('id') + ->on('ad_employers') + ->onDelete('cascade'); + + $table->unsignedBigInteger('job_title_id')->nullable(); + //внешний ключ, ссылается на поле id таблицы job_titles + $table->foreign('job_title_id', 'key_job_title_id') + ->references('id') + ->on('job_titles') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('ad_jobs', function (Blueprint $table) { + $table->dropIndex(['key_ad_employer_id']); + $table->dropIndex(['key_job_title_id']); + $table->dropColumn('job_title_id'); + $table->dropColumn('ad_employer_id'); + }); + } +}; diff --git a/database/migrations/2023_09_06_100450_alter_ad_employers_table.php b/database/migrations/2023_09_06_100450_alter_ad_employers_table.php new file mode 100644 index 0000000..cc15d8d --- /dev/null +++ b/database/migrations/2023_09_06_100450_alter_ad_employers_table.php @@ -0,0 +1,32 @@ +string('name', 255)->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('ad_employers', function (Blueprint $table) { + $table->dropColumn('name'); + }); + } +}; diff --git a/resources/views/admin/ad_employers/index.blade.php b/resources/views/admin/ad_employers/index.blade.php index fe7b5d0..fd8d1fe 100644 --- a/resources/views/admin/ad_employers/index.blade.php +++ b/resources/views/admin/ad_employers/index.blade.php @@ -1,10 +1,10 @@ -@extends('layout.admin', ['title' => 'Админка - Работодатели']) +@extends('layout.admin', ['title' => 'Админка - Вакансии']) @section('script') @endsection @section('search') -
-
- + + @foreach ($ad->jobs as $title) + +{{$title->name}}
+ +/ {{$title->name}}
+ + @endforeach№ | +Название группы | +Создатель группы | +Кол-во участников | +Дата регистрации | +Изменить | +
---|---|---|---|---|---|
+ {{$group->id}} + | ++ {{$group->name_group}} + | ++ {{$group->user->name}} + | ++ {{$group->ingroup->count()}} + | ++ {{ $group->created_at }} + | ++ Изменить + | +
+ Модерация отзывов о работодателе +
+№ | +От юзера | +К юзеру | +Заголовок | +Отклик | +Дата | +
---|---|---|---|---|---|
+ {{$msg->id}} + | ++ {{$msg->user_from->name}} ({{$msg->user_from->id}}) + | ++ {{$msg->user_to->name}} ({{$msg->user_to->id}}) + | ++ {{$msg->title}} + | +
+
+
+
+ @if ($msg->response->count())
+ Да
+ @else
+ Нет
+ @endif
+
+ |
+ + {{ $msg->created_at }} + | +