File manager - Edit - /var/www/payraty/inventory_main/app/Http/Controllers/Admin/Administration/RolesController.php
Back
<?php namespace App\Http\Controllers\Admin\Administration; use App\DataTables\RoleDataTable; use App\Http\Requests\RoleRequest; use App\Services\Role\RoleService; use App\Http\Controllers\Controller; use Spatie\Permission\Models\Role; use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request; use PDF; use Excel; use App\Exports\RolesExport; class RolesController extends Controller { protected $roleService; /** * __construct * * @param mixed $roleService * @return void */ public function __construct(RoleService $roleService) { $this->roleService = $roleService; $this->middleware(['permission:List Role'])->only(['index']); $this->middleware(['permission:Add Role'])->only(['create']); $this->middleware(['permission:Edit Role'])->only(['edit']); $this->middleware(['permission:Show Role'])->only(['show']); $this->middleware(['permission:Delete Role'])->only(['destroy']); } /** * index * * @param mixed $dataTable * @return void */ public function index(RoleDataTable $dataTable) { set_page_meta(__('custom.roles')); $user = Auth::user(); $orgId = $user->organisation_id; $roles = Role::where('organisation_id', $orgId)->paginate(10); // return $dataTable->render('admin.administration.roles.index'); return view('admin.administration.roles.index', compact('roles')); } public function filter(Request $request) { $user = Auth::user(); $orgId = $user->organisation_id; $period = $request->get('period', 'all'); $query = Role::where('organisation_id', $orgId); switch ($period) { case 'monthly': $query->whereMonth('created_at', now()->month); break; case 'yearly': $query->whereYear('created_at', now()->year); break; // 'all' case doesn't need additional filtering } $roles = $query->paginate(10); if ($request->ajax()) { return response()->json([ 'roles' => $roles ]); } // Fallback for non-AJAX requests return redirect()->route('admin.administration.roles.index'); } public function search(Request $request) { $user = Auth::user(); $orgId = $user->organisation_id; $searchTerm = $request->get('q'); $roles = Role::where('organisation_id', $orgId) ->where(function ($query) use ($searchTerm) { $query->where('name', 'LIKE', "%{$searchTerm}%"); }) ->paginate(10); if ($request->ajax()) { return response()->json([ 'roles' => $roles ]); } // Fallback for non-AJAX requests return view('admin.administration.roles.index', compact('roles')); } /** * exportRoles * * @param mixed $request * @return void */ public function exportRoles(Request $request) { $roles = []; $type = $request->type; $user = Auth::user(); $orgId = $user->organisation_id; $roles = Role::where('organisation_id', $orgId)->get(); $name = 'Role_' . now()->format('YmdHis'); if ($type == 'pdf') { $pdf = PDF::loadView('admin.administration.roles.pdf.index', ['roles' => $roles]); return $pdf->download($name . '.pdf'); } else if ($type == 'csv') { return Excel::download(new RolesExport($roles), $name . '.csv'); } else if ($type == 'excel') { return Excel::download(new RolesExport($roles), $name . '.xlsx'); } } /** * create * * @return void */ public function create() { $permissions = $this->roleService->getParentPermissions(); set_page_meta(__('custom.add_role')); return view('admin.administration.roles.create', compact('permissions')); } /** * store * * @param mixed $request * @return void */ public function store(RoleRequest $request) { $data = $request->validated(); $user = Auth::user(); $orgId = $user->organisation_id; if ($this->roleService->createOrUpdate($orgId, $data)) { flash(__('custom.role_create_successful'))->success(); } else { flash(__('custom.role_create_failed'))->error(); } return redirect()->route('admin.roles.index'); } /** * show * * @param mixed $id * @return void */ public function show($id) { $role = $this->roleService->get($id); return view('admin.administration.roles.show', compact('role')); } /** * edit * * @param mixed $id * @return void */ public function edit($id) { $role = $this->roleService->get($id); $permissions = $this->roleService->getParentPermissions(); $parents_id = []; $role_permission = []; if ($role->permissions) { foreach ($role->permissions as $key => $value) { array_push($role_permission, $value->id); array_push($parents_id, $value->parent_id); } } set_page_meta(__('custom.edit_role')); return view('admin.administration.roles.edit', compact('role', 'permissions', 'parents_id', 'role_permission')); } /** * update * * @param mixed $request * @param mixed $id * @return void */ public function update(RoleRequest $request, $id) { $data = $request->validated(); $user = Auth::user(); $orgId = $user->organisation_id; if ($this->roleService->createOrUpdate($orgId, $data, $id)) { flash(__('custom.role_updated_successful'))->success(); } else { flash(__('custom.role_updated_failed'))->error(); } return redirect()->route('admin.roles.index'); } /** * destroy * * @param mixed $id * @return void */ public function destroy($id) { if ($this->roleService->delete($id)) { flash(__('custom.role_deleted_successful'))->success(); } else { flash(__('custom.role_deleted_failed'))->error(); } return redirect()->route('admin.roles.index'); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings