Файловый менеджер - Редактировать - /home/clickysoft/public_html/travel-guru.clickysoft.net/app/Repositories/ManageUserRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\ManageUserRepositoryInterface; use App\Models\User; use App\Notifications\UserWelcome; use Illuminate\Support\Facades\Auth; use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; use Yajra\DataTables\Facades\DataTables; use Carbon\Carbon; class ManageUserRepository implements ManageUserRepositoryInterface { public function getAllUser() { return User::all(); } public function getUserById($userId) { return User::findOrFail($userId); } public function deleteUser($userId) { $user = User::where('id', $userId)->first(); if (!empty($user)) { $user->syncRoles([]); $user->delete(); return redirect()->back()->with('success_msg', 'User successfully deleted.'); } abort(404); } public function createUser($req) { $role = Role::find($req->role); if (empty($role)) { return redirect()->back()->withInput()->with('error_msg', 'Role is invalid.'); } $user = User::create([ 'full_name' => $req->full_name, 'email' => $req->email, 'password' => $req->password, 'is_verified' => 1, 'phone_number' => $req->phone_number, ]); $user->assignRole([$role->id]); $credentials = '<br /><strong>Username:</strong> ' . $req->email . '<br /><strong>Password:</strong> ' . $req->password; // $user->notify((new UserWelcome($credentials))->delay(now()->addSeconds(5))); return redirect()->route('manage.users')->with('success_msg', 'User successfully added.'); } public function updateUser($userId, $req) { $user = User::where('id', $userId)->first(); if (!empty($user)) { $userData['full_name'] = $req->full_name; $userData['email'] = $req->email; if (!empty($req->password)) { $userData['password'] = $req->password; } $userData['phone_number'] = $req->phone_number; $user->update($userData); if (!empty($req->password)) { $credentials = '<br /><strong>Username:</strong> ' . $req->email . '<br /><strong>New Password:</strong> ' . $req->password; // $user->notify((new UserWelcome($credentials))->delay(now()->addSeconds(5))); } return redirect()->route('manage.users')->with('success_msg', 'User successfully updated.'); } return redirect()->back()->withInput()->with('error_msg', 'User not found.'); } public function getDataTable() { $userRole = Role::where('name', 'User')->first(); $query = User::whereHas('roles', function ($query) use ($userRole) { $query->where('role_id', $userRole->id); }); return Datatables::of($query) ->filter(function ($instance) { $search = request('search')['value']; if (!empty($search)) { $instance->where(function ($w) use ($search) { $w->orWhere('full_name', 'LIKE', "%$search%") ->orWhere('email', 'LIKE', "%$search%") ->orWhere('created_at', 'LIKE', "%$search%"); }); } }) ->editColumn('created_at', function ($obj) { return Carbon::createFromFormat('Y-m-d H:i:s', $obj->created_at)->format('Y-m-d'); }) ->editColumn('role', function ($obj) { return isset($obj->roles[0]) ? $obj->roles[0]?->name : "NA"; }) ->editColumn('is_active', function ($obj) { $isChecked = ""; if (!empty($obj->is_active)) { $isChecked = "checked"; } $switchBtn = '<label class="switch switch-success"> <input type="checkbox" class="switch-input" ' . $isChecked . ' onclick="changeStatus(`' . route('user.change.status', $obj->id) . '`)" /> <span class="switch-toggle-slider"> <span class="switch-on"> <i class="bx bx-check"></i> </span> <span class="switch-off"> <i class="bx bx-x"></i> </span> </span> </label>'; return $switchBtn; }) ->addColumn('action', function ($obj) { $buttons = '<div class="btn-group"><a class="btn btn-primary btn-sm redirect-btn" href="' . route('user.detail', $obj->id) . '">View</a> </div>'; return $buttons; })->rawColumns(['is_active', 'action'])->make(true); } public function changeStatus($userId) { $msg = 'Something went wrong.'; $code = 400; $user = $this->getUserById($userId); if (!empty($user)) { $user->update([ 'is_active' => !$user->is_active ]); $msg = "User status successfully changed."; $code = 200; } return response()->json(['msg' => $msg], $code); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка