diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index fa3bc1a..a261d8f 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -8,6 +8,7 @@ use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Validator; class AdminController extends Controller { @@ -27,21 +28,44 @@ class AdminController extends Controller } public function create(Request $request) { - $request->validate([ + + $rules = [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8|confirmed', - ]); - - User::create([ - 'name' => $request->name, - 'email' => $request->email, - 'password' => Hash::make($request->password), - ]); - - return redirect() - ->route('admin.login') - ->with('success', 'Вы успешно зарегистрировались'); + ]; + + $messages = [ + 'required' => 'Укажите обязательное поле «:attribute»', + 'confirmed' => 'Пароли не совпадают', + 'email' => 'Введите корректный email', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ], + ]; + + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return back()->withErrors($validator)->withInput(); //->route('admin.register') + + } else { + $params = $request->all(); + + User::create([ + 'name' => $request->name, + 'email' => $request->email, + 'password' => Hash::make($request->password), + ]); + return redirect() + ->route('admin.login') + ->with('success', 'Вы успешно зарегистрировались'); + } } public function login() { @@ -50,39 +74,59 @@ class AdminController extends Controller // Аутентификация public function autenticate(Request $request) { - $request->validate([ + //$request->validate( + $rules = [ 'email' => 'required|string|email', 'password' => 'required|string', - ]); + ]; - $credentials = $request->only('email', 'password'); + $messages = [ + 'required' => 'Укажите обязательное поле «:attribute»', + 'email' => 'Введите корректный email', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ], + ]; - if (Auth::attempt($credentials, $request->has('remember'))) { - if (is_null(Auth::user()->email_verified_at)) - { - Auth::logout(); - return redirect() - ->route('admin.login') - ->withErrors('Адрес почты не подтвержден'); - } + $validator = Validator::make($request->all(), $rules, $messages); - if (!Auth::user()->admin) { - Auth::logout(); - return redirect() - ->route('admin.login') - ->withErrors('Вы не являетесь админом!'); + if ($validator->fails()) { + return back()->withErrors($validator)->withInput(); - } + } else { - return redirect() - ->route('admin.index') - ->with('success', 'Вы вошли в личный кабинет.'); + $credentials = $request->only('email', 'password'); + + if (Auth::attempt($credentials, $request->has('remember'))) { + + if (is_null(Auth::user()->email_verified_at)) { + Auth::logout(); + return back()->withErrors('Адрес почты не подтвержден')->withInput(); + } + + if (!Auth::user()->admin) { + Auth::logout(); + return //redirect()->route('admin.login') + back()->withErrors('Вы не являетесь админом!')->withInput();; + + } + + return redirect() + ->route('admin.index') + ->with('success', 'Вы вошли в личный кабинет.'); + } } return redirect() ->route('admin.login') - ->withErrors('Неверный логин или пароль!'); + ->withErrors('Неверный логин или пароль!')->withInput(); + } public function logout() { @@ -99,6 +143,20 @@ class AdminController extends Controller return view('admin.index', compact('all_employer', 'all_user', 'all_worker', 'all_admin')); } + public function index_admin(Request $request) { + if ($request->ajax()) { + $user = User::find($request->id); + $request->offsetUnset('id'); + $user->update($request->all()); + } + + $users = User::where('admin', '1')->paginate(15); + if ($request->ajax()) { + return view('admin.users.index_ajax', compact('users')); + } else { + return view('admin.users.index', compact('users')); + } + } } diff --git a/app/Http/Controllers/Admin/EmployersController.php b/app/Http/Controllers/Admin/EmployersController.php new file mode 100644 index 0000000..8305025 --- /dev/null +++ b/app/Http/Controllers/Admin/EmployersController.php @@ -0,0 +1,25 @@ +ajax()) { + $user = User::find($request->id); + $request->offsetUnset('id'); + $user->update($request->all()); + } + + $users = User::where('is_worker', '0')->paginate(15); + if ($request->ajax()) { + return view('admin.employer.index_ajax', compact('users')); + } else { + return view('admin.employer.index', compact('users')); + } + } +} diff --git a/app/Http/Controllers/Admin/UsersController.php b/app/Http/Controllers/Admin/UsersController.php new file mode 100644 index 0000000..6d02900 --- /dev/null +++ b/app/Http/Controllers/Admin/UsersController.php @@ -0,0 +1,27 @@ +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.index_ajax', compact('users')); + } else { + return view('admin.users.index', compact('users')); + } + } + +} diff --git a/app/Http/Controllers/Admin/WorkersController.php b/app/Http/Controllers/Admin/WorkersController.php new file mode 100644 index 0000000..afa5294 --- /dev/null +++ b/app/Http/Controllers/Admin/WorkersController.php @@ -0,0 +1,26 @@ +ajax()) { + $user = User::find($request->id); + $request->offsetUnset('id'); + $user->update($request->all()); + } + + $users = User::where('is_worker', '1')->paginate(15); + + if ($request->ajax()) { + return view('admin.worker.index_ajax', compact('users')); + } else { + return view('admin.worker.index', compact('users')); + } + } +} diff --git a/app/Models/Employer.php b/app/Models/Employer.php index 54327c5..f3d74d9 100644 --- a/app/Models/Employer.php +++ b/app/Models/Employer.php @@ -8,4 +8,26 @@ use Illuminate\Database\Eloquent\Model; class Employer extends Model { use HasFactory; + + protected $fillable = [ + 'name_company', + 'email', + 'telephone', + 'logo', + 'rate', + 'user_id', + 'sort', + 'text', + 'address', + 'map', + 'site', + ]; + + /* + * Связь таблицы users с таблицей employers + */ + public function users() { + return $this->belongsTo(User::class, 'user_id'); + } + } diff --git a/app/Models/User.php b/app/Models/User.php index 23b4063..99e5e2c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -21,6 +21,18 @@ class User extends Authenticatable 'name', 'email', 'password', + 'admin', + 'telephone', + 'surname', + 'name_man', + 'surname2', + 'is_worker', + 'is_lookin', + 'is_message', + 'is_public', + 'is_remove', + 'is_ban', + 'is_new', ]; /** @@ -41,4 +53,46 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + + /* + * Связь Пользователей системы с работодателями + * users - employers + */ + public function employers() { + return $this->hasMany(Employer::class); + } + + /* + * Связь Пользователей системы с работниками + * users - workers + */ + public function workers() { + return $this->hasMany(Worker::class); + } + + /* + * Связь Пользователей системы с группами юзеров + * users - group_users + */ + public function groups() { + return $this->hasMany(Group_user::class); + } + + /* + * Связь Пользователей системы с ссобщениями + * users - messages + */ + public function messages() { + return $this->hasMany(Message::class); + } + + /* + * Связь Пользователей системы с статистика + * users - static_workers + */ + public function static_user() { + return $this->hasMany(Static_worker::class); + } + + } diff --git a/app/Models/Worker.php b/app/Models/Worker.php index 5c31285..564e122 100644 --- a/app/Models/Worker.php +++ b/app/Models/Worker.php @@ -8,4 +8,43 @@ use Illuminate\Database\Eloquent\Model; class Worker extends Model { use HasFactory; + + protected $fillable = [ + 'user_id', + 'status_work', + 'position_work', + 'telephone', + 'telephone2', + 'persent_anketa', + 'photo', + 'email_data', + 'status_profile', + 'old_year', + 'experience', + 'en_is', + 'education', + 'email', + 'interpassport', + 'mk', + 'vvp', + 'vlm', + 'reka_diplom', + 'more_diplom', + 'mpss', + 'tanker', + 'gmssb', + 'resume', + 'sort', + 'updated_at', + 'text', + 'address', + 'city', + ]; + + /* + * Связь таблицы users с таблицей workers + */ + public function users() { + return $this->belongsTo(User::class, 'user_id'); + } } diff --git a/database/migrations/2023_05_17_090650_alter_group_users_table.php b/database/migrations/2023_05_17_090650_alter_group_users_table.php new file mode 100644 index 0000000..de1aaa6 --- /dev/null +++ b/database/migrations/2023_05_17_090650_alter_group_users_table.php @@ -0,0 +1,32 @@ +bigInteger('user_id')->nullable(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('group_users', function (Blueprint $table) { + $table->dropColumn('user_id'); + }); + } +}; diff --git a/database/migrations/2023_05_17_090749_alter_messages_table.php b/database/migrations/2023_05_17_090749_alter_messages_table.php new file mode 100644 index 0000000..624fafa --- /dev/null +++ b/database/migrations/2023_05_17_090749_alter_messages_table.php @@ -0,0 +1,34 @@ +string('title', 255)->nullable(true); + $table->string('file', 255)->nullable(true); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('messages', function (Blueprint $table) { + $table->dropColumn('title'); + $table->dropColumn('file'); + }); + } +}; diff --git a/database/migrations/2023_05_17_090923_alter_employers_table.php b/database/migrations/2023_05_17_090923_alter_employers_table.php new file mode 100644 index 0000000..a212113 --- /dev/null +++ b/database/migrations/2023_05_17_090923_alter_employers_table.php @@ -0,0 +1,36 @@ +string('address', 255)->nullable(true); + $table->string('map', 255)->nullable(true); + $table->string('site', 255)->nullable(true); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('employers', function (Blueprint $table) { + $table->dropColumn('address'); + $table->dropColumn('map'); + $table->dropColumn('site'); + }); + } +}; diff --git a/database/migrations/2023_05_17_090944_alter_workers_table.php b/database/migrations/2023_05_17_090944_alter_workers_table.php new file mode 100644 index 0000000..cb46c2d --- /dev/null +++ b/database/migrations/2023_05_17_090944_alter_workers_table.php @@ -0,0 +1,36 @@ +string('address', 255)->nullable(true); + $table->string('city', 255)->nullable(true); + $table->text('text')->nullable(true); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('workers', function (Blueprint $table) { + $table->dropColumn('address'); + $table->dropColumn('city'); + $table->dropColumn('text'); + }); + } +}; diff --git a/database/migrations/2023_05_17_095512_alter_users_table.php b/database/migrations/2023_05_17_095512_alter_users_table.php new file mode 100644 index 0000000..cb3e2cf --- /dev/null +++ b/database/migrations/2023_05_17_095512_alter_users_table.php @@ -0,0 +1,36 @@ +boolean('is_remove')->default(false); + $table->boolean('is_ban')->default(false); + $table->boolean('is_new')->default(true); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('is_remove'); + $table->dropColumn('is_ban'); + $table->dropColumn('is_new'); + }); + } +}; diff --git a/resources/views/admin/employer/index.blade.php b/resources/views/admin/employer/index.blade.php new file mode 100644 index 0000000..b0154d3 --- /dev/null +++ b/resources/views/admin/employer/index.blade.php @@ -0,0 +1,106 @@ +@extends('layout.admin', ['title' => 'Админка - Работодатели']) + +@section('script') + +@endsection + +@section('content') +
№ | +Название компании | +Email/Телефон | +Имя | +Дата регистрации | +Изменить | +Блокировать | +
---|---|---|---|---|---|---|
+ {{$user->id}} + | ++ {{$user->name}} + | +
+
+
+
+
+
+
+ {{ empty($user->employers->email) ? $user->email : $user->employers->email }} ++ {{ empty($user->employers->telephone) ? $user->telephone : $user->employers->telephone }} + + |
+ + {{ $user->name_man }} + | ++ {{ $user->created_at }} + | ++ Изменить + | ++ is_ban) ? "checked" : "" }}/> + | +
№ | +Название компании | +Email/Телефон | +Имя | +Дата регистрации | +Изменить | +Блокировать | +
---|---|---|---|---|---|---|
+ {{$user->id}} + | ++ {{$user->name}} + | +
+
+
+
+
+
+
+ {{ empty($user->employers->email) ? $user->email : $user->employers->email }} ++ {{ empty($user->employers->telephone) ? $user->telephone : $user->employers->telephone }} + + |
+ + {{ $user->name_man }} + | ++ {{ $user->created_at }} + | ++ Изменить + | ++ is_ban) ? "checked" : "" }}/> + | +