From 9b4580039f5ceae97c06059b629e07965e8214a9 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: Mon, 30 Oct 2023 14:04:48 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=B4=D0=B8=D0=B0=20=D1=81=D1=83=D1=89?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C,=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0?= =?UTF-8?q?=BE=D1=81=D1=82=D0=B8=20=D0=B2=20=D0=B1=D0=B4,=20=D1=84=D0=B8=D0=BB?= =?UTF-8?q?=D1=8C=D1=82=D1=80=D1=8B=20=D0=B2=20=D0=B2=D0=B0=D0=BA=D0=B0=D0=BD?= =?UTF-8?q?=D1=81=D0=B8=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/Ad_EmployersController.php | 40 +++++++- app/Http/Controllers/Admin/UsersController.php | 35 ++++++- app/Http/Controllers/Admin/WorkersController.php | 6 +- app/Http/Controllers/MediaController.php | 24 +++++ app/Http/Requests/BaseUserRequest.php | 13 ++- app/Models/Media.php | 24 +++++ app/Models/User.php | 4 + .../2023_10_28_112853_create_media_table.php | 33 +++++++ resources/views/admin/ad_employers/index.blade.php | 22 ++++- resources/views/admin/find_ad_employer.blade.php | 41 ++++++++ resources/views/admin/media/index.blade.php | 103 ++++++++++++++++++++ resources/views/admin/users/form.blade.php | 30 +++++- resources/views/admin/users/index_bd.blade.php | 12 ++- .../views/admin/users/index_bd_ajax.blade.php | 59 ++++++++--- resources/views/admin/worker/index.blade.php | 20 ++++ resources/views/layout/admin.blade.php | 42 ++++++++ routes/web.php | 4 + 17 files changed, 486 insertions(+), 26 deletions(-) create mode 100644 app/Http/Controllers/MediaController.php create mode 100644 app/Models/Media.php create mode 100644 database/migrations/2023_10_28_112853_create_media_table.php create mode 100644 resources/views/admin/find_ad_employer.blade.php create mode 100644 resources/views/admin/media/index.blade.php diff --git a/app/Http/Controllers/Admin/Ad_EmployersController.php b/app/Http/Controllers/Admin/Ad_EmployersController.php index c5c1158..b0083c5 100644 --- a/app/Http/Controllers/Admin/Ad_EmployersController.php +++ b/app/Http/Controllers/Admin/Ad_EmployersController.php @@ -31,13 +31,47 @@ class Ad_EmployersController extends Controller } } - $ad_employers = Ad_employer::with('employer')->with('jobs') - ->where('is_remove', '0')->OrderBy('updated_at', 'desc')->paginate(15); + $select_job = Job_title::query()->active()->get(); + $all_ad = Ad_employer::with('employer')->with('jobs') + ->where('is_remove', '0')->get()->count(); + + $ad_employers = Ad_employer::where('is_remove', '0'); + + $find_job = ""; + if (isset($request->category_job)) { + if ($request->category_job != 'Все вакансии') { + $find_job = $request->category_job; + $ad_employers = $ad_employers->WhereHas('jobs', function($query) use ($find_job){ + return $query->where('name', 'LIKE', '%'.$find_job.'%'); + }); + } + } else { + $ad_employers = $ad_employers->with('jobs'); + } + + $find_key = ""; + if (isset($request->find)) { + $find_key = $request->find; + $ad_employers = $ad_employers->whereHas('employer', function($query) use($find_key) { + $query->Where('name_company', 'LIKE', "%$find_key%"); + $query->orWhere('name', 'LIKE', "%$find_key%"); + }); + + } else { + $ad_employers = $ad_employers->with('employer'); + } + + $ad_employers = $ad_employers->OrderBy('updated_at', 'desc')->paginate(15); if ($request->ajax()) { return view('admin.ad_employers.index_ajax', compact('ad_employers', 'params')); } else { - return view('admin.ad_employers.index', compact('ad_employers', 'title')); + return view('admin.ad_employers.index', compact('ad_employers', + 'title', + 'all_ad', + 'find_job', + 'find_key', + 'select_job')); } } diff --git a/app/Http/Controllers/Admin/UsersController.php b/app/Http/Controllers/Admin/UsersController.php index 2fd3c2c..2ba22d8 100644 --- a/app/Http/Controllers/Admin/UsersController.php +++ b/app/Http/Controllers/Admin/UsersController.php @@ -4,7 +4,9 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Http\Requests\BaseUserRequest; +use App\Models\Job_title; use App\Models\User; +use App\Models\Worker; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; @@ -62,26 +64,40 @@ class UsersController extends Controller } public function add_bd() { - return view('admin.users.add'); + $list_job_titles = Job_title::query()->active()->orderBy('name', 'asc')->get(); + return view('admin.users.add', compact('list_job_titles')); } public function add_store_bd(BaseUserRequest $request) { $params = $request->all(); + $position_work = $request->position_work; if ($request->has('file')) { $params['file'] = $request->file('file')->store('basedata', 'public'); } + if (isset($request->name)) { + $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2; + } + $user = User::create($params); + $user_id = $user->id; + $worker = new Worker(); + $worker->position_work = $position_work; + $worker->user_id = $user_id; + $worker->save(); + return redirect()->route('admin.basedata'); } public function edit_bd(User $user) { - return view('admin.users.edit', compact('user')); + $list_job_titles = Job_title::query()->active()->orderBy('name', 'asc')->get(); + return view('admin.users.edit', compact('user', 'list_job_titles')); } public function update_bd(BaseUserRequest $request, User $user) { $params = $request->all(); + $position_work = $request->position_work; if ($request->has('file')) { if (!empty($user->file)) Storage::delete($user->file); @@ -90,7 +106,22 @@ class UsersController extends Controller if (!empty($user->image)) $params['file'] = $user->file; } + if (isset($request->name)) { + $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2; + } + $user->update($params); + if (isset($user->workers[0]->id)) { + $worker = Worker::find($user->workers[0]->id); + $worker->position_work = $position_work; + $worker->save(); + } else { + $worker = new Worker(); + $worker->user_id = $user->id; + $worker->position_work = $position_work; + $worker->save(); + } + return redirect()->route('admin.basedata'); } diff --git a/app/Http/Controllers/Admin/WorkersController.php b/app/Http/Controllers/Admin/WorkersController.php index 39e1ea1..ce8dbc6 100644 --- a/app/Http/Controllers/Admin/WorkersController.php +++ b/app/Http/Controllers/Admin/WorkersController.php @@ -33,7 +33,8 @@ class WorkersController extends Controller } $status_work = Job_title::query()->active()->orderBy('name')->get(); - $users = User::with('jobtitles')->where('is_worker', '1'); + $users = User::with('jobtitles')->worker()->realuser(); + $all_worker = $users->count(); $find_status_work = ""; if (isset($request->status_work)) { @@ -126,7 +127,8 @@ class WorkersController extends Controller 'find_key', 'find_status_work', 'status_work', - 'status_wor')); + 'status_wor', + 'all_worker')); } } diff --git a/app/Http/Controllers/MediaController.php b/app/Http/Controllers/MediaController.php new file mode 100644 index 0000000..8d26ab0 --- /dev/null +++ b/app/Http/Controllers/MediaController.php @@ -0,0 +1,24 @@ +OrderBy('id', 'desc')->paginate(); + return view('admin.media.index', compact('Media')); + } + + public function delete(Media $media) { + if (!empty($media->file)){ + Storage::delete($media->file); + } + + $media->delete(); + return redirect()->route('admin.media'); + } +} diff --git a/app/Http/Requests/BaseUserRequest.php b/app/Http/Requests/BaseUserRequest.php index e202c39..414943d 100644 --- a/app/Http/Requests/BaseUserRequest.php +++ b/app/Http/Requests/BaseUserRequest.php @@ -23,11 +23,17 @@ class BaseUserRequest extends FormRequest */ public function rules() { + + $unique ='|unique:users'; + if (in_array($this->route()->getName(), ['admin.update-basedata'])) { + $unique = '|unique:users,email,'.$this->user->id; + } + return [ - 'name' => 'required|min:3|max:255', + //'name' => 'required|min:3|max:255', 'surname' => 'required|min:3|max:255', 'name_man' => 'required|min:3|max:255', - 'email' => 'required|email|min:5', + 'email' => 'required|email|min:5'.$unique, ]; } @@ -42,7 +48,8 @@ class BaseUserRequest extends FormRequest 'string' => 'Поле «:attribute» должно быть не больше :max символов', 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' ], - 'email' => 'Введите корректный емайл' + 'email' => 'Введите корректный емайл', + 'unique' => 'Емайл должен быть уникальным', ]; } diff --git a/app/Models/Media.php b/app/Models/Media.php new file mode 100644 index 0000000..382f3d4 --- /dev/null +++ b/app/Models/Media.php @@ -0,0 +1,24 @@ +belongsTo(User::class, 'user_id'); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 1d28fcc..cc5ef62 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -131,6 +131,10 @@ class User extends Authenticatable return $query->where('is_remove', '=', '0'); } + public function scopeWorker($query) { + return $query->where('is_worker', '=', '1'); + } + public function scopeBaseuser($query) { return $query->where('is_bd', '=', '1'); } diff --git a/database/migrations/2023_10_28_112853_create_media_table.php b/database/migrations/2023_10_28_112853_create_media_table.php new file mode 100644 index 0000000..ff28fd3 --- /dev/null +++ b/database/migrations/2023_10_28_112853_create_media_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('file', 255)->nullable(false); + $table->bigInteger('user_id')->nullable(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('media'); + } +}; diff --git a/resources/views/admin/ad_employers/index.blade.php b/resources/views/admin/ad_employers/index.blade.php index b1bfa6a..274209e 100644 --- a/resources/views/admin/ad_employers/index.blade.php +++ b/resources/views/admin/ad_employers/index.blade.php @@ -38,10 +38,30 @@ @endsection @section('search') - + @include('admin.find_ad_employer', ['select_job' => $select_job]) @endsection @section('content') +
+ +
+
+ + + +
+
+

+ Всего вакансий +

+

+ {{ $all_ad }} +

+
+
+
+ diff --git a/resources/views/admin/find_ad_employer.blade.php b/resources/views/admin/find_ad_employer.blade.php new file mode 100644 index 0000000..4fc1907 --- /dev/null +++ b/resources/views/admin/find_ad_employer.blade.php @@ -0,0 +1,41 @@ +
+ +
+
+
+
+
+ +
+
+ +
+
diff --git a/resources/views/admin/media/index.blade.php b/resources/views/admin/media/index.blade.php new file mode 100644 index 0000000..82e8cd5 --- /dev/null +++ b/resources/views/admin/media/index.blade.php @@ -0,0 +1,103 @@ +@extends('layout.admin', ['title' => 'Админка - Медиа проекта']) + +@section('script') + +@endsection + +@section('modal') + +@endsection + +@section('search') + +@endsection + +@section('content') + +
+
+ + + + + + + + + + + + @foreach($Media as $img) + + + + + + + + + + @endforeach + +
КартинкаЮзерДата загрузкиРедактировать
+ {{$img->id}} + + + +
+
+ @if (isset($img->user->id)) +

+ {{$img->user->name_man}} {{$img->user->surname}} {{$img->user->surname2}} +

+

+ ID: {{$img->id}} +

+ @endif +
+
+
+ {{$img->created_at}} + +
+ @csrf + @method('DELETE') + +
+
+
+ +
+ appends($_GET)->links('admin.pagginate'); ?> +
+
+@endsection diff --git a/resources/views/admin/users/form.blade.php b/resources/views/admin/users/form.blade.php index 85e9036..7abcce7 100644 --- a/resources/views/admin/users/form.blade.php +++ b/resources/views/admin/users/form.blade.php @@ -1,5 +1,5 @@
-
- + + + + @if (isset($user->jobtitles[0]->name)) + {{ $user->jobtitles[0]->name }} + @else + - + @endif diff --git a/resources/views/admin/users/index_bd_ajax.blade.php b/resources/views/admin/users/index_bd_ajax.blade.php index df23471..b112072 100644 --- a/resources/views/admin/users/index_bd_ajax.blade.php +++ b/resources/views/admin/users/index_bd_ajax.blade.php @@ -6,9 +6,11 @@ > № Имя - Email/логин - Статус + Email/телефон + Должность + Анкета Дата регистрации + Изменить @@ -33,8 +35,11 @@ --> - {{ $user->name }} + + + {{ $user->name }} +
+ + + @if (isset($user->jobtitles[0]->name)) + {{ $user->jobtitles[0]->name }} + @else + - @endif - @if ($user->is_bd) - - База данных - + + + + @if (isset($user->workers[0]->id)) + + @endif + @isset($user->file) + Скачать + @else +

-

+ @endisset {{ date('d.m.Y', strtotime($user->created_at)) }} + + +
+ Изменить | + @csrf + @method('DELETE') + +
+ @endforeach diff --git a/resources/views/admin/worker/index.blade.php b/resources/views/admin/worker/index.blade.php index b3ee5bd..72a46fa 100644 --- a/resources/views/admin/worker/index.blade.php +++ b/resources/views/admin/worker/index.blade.php @@ -43,6 +43,26 @@ @endsection @section('content') +
+ +
+
+ + + +
+
+

+ Всего соискателей +

+

+ {{ $all_worker }} +

+
+
+
+