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 }} +
+№ | +Картинка | +Юзер | +Дата загрузки | +Редактировать | +
---|---|---|---|---|
+ {{$img->id}} + | ++ + | + +
+
+
+
+ @if (isset($img->user->id))
+
+ + {{$img->user->name_man}} {{$img->user->surname}} {{$img->user->surname2}} + ++ ID: {{$img->id}} + + @endif + |
+ + {{$img->created_at}} + | + ++ + | +
-
+ @endisset+ Всего соискателей +
++ {{ $all_worker }} +
+