Файловый менеджер - Редактировать - /home/clickysoft/public_html/travel-guru.clickysoft.net/app/Repositories/ManageTravelAgentRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\ManageTravelAgentRepositoryInterface; use App\Models\Role as ModelsRole; use App\Models\User; use App\Notifications\UserWelcome; use Carbon\Carbon; use Illuminate\Support\Facades\Auth; use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; use Yajra\DataTables\Facades\DataTables; class ManageTravelAgentRepository implements ManageTravelAgentRepositoryInterface { public function getAllAgent() { return User::all(); } public function getAgentById($userId) { return User::findOrFail($userId); } public function deleteAgent($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 createAgent($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 updateAgent($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', 'Travel Agent')->first(); $query = User::whereHas('roles', function ($query) use ($userRole) { $query->where('role_id', $userRole->id); }) ->where('id', '!=', Auth::id()); // ->orderBy('id', 'desc'); 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%"); if (strtolower($search) === "unverified") { $w->orWhere('is_verified', 0); } elseif (strtolower($search) === "verified") { $w->orWhere('is_verified', 1); } }); } }) ->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('travel.agent.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('travel.agent.detail', $obj->id) . '">View</a> <a class="btn btn-info btn-sm redirect-btn" href="' . route('travel-agent.assign-badges', $obj->id) . '">Assign Badges</a> </div>'; return $buttons; })->rawColumns(['is_active', 'action'])->make(true); } public function changeStatus($userId) { $msg = 'Something went wrong.'; $code = 400; $user = $this->getAgentById($userId); if (!empty($user)) { $user->update([ 'is_active' => !$user->is_active ]); $msg = "Travel Agent status successfully changed."; $code = 200; } return response()->json(['msg' => $msg], $code); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка