芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/public_html/design.pulsehost.co.uk/application/app/Models/Role.php
role->role_name); } /** * relatioship business rules: * - the Project can have many Estimates * - the Estimate belongs to one Project */ public function users() { return $this->hasMany('App\Models\User', 'role_id', 'role_id'); } /** * Get the current user's permissions for any module that is stored in the 'modules' field in the 'roles' table. * Usage: auth()->user()->role->module->services (none/view/manage) * This has error handling so that non-existent modules will not throw an error but just return 'none'. * Example: auth()->user()->role->module->foobar (returns 'none') */ protected function getModuleAttribute() { //return none for user not logged in if (!auth()->check()) { return 'none'; } try { // Decode the JSON or return an empty array if null $modules = json_decode($this->attributes['modules'] ?? '[]', true); // Transform module permissions into a key-value array $permissions = []; foreach ($modules as $module) { $key = str_replace(' ', '_', strtolower($module['module_name'])); $permissions[$key] = strtolower($module['module_permission']); } // Return an anonymous class with dynamic property handling return new class($permissions) { protected $permissions; public function __construct(array $permissions) { $this->permissions = $permissions; } public function __get($key) { // Return the permission if it exists, otherwise return 'none' return $this->permissions[$key] ?? 'none'; } }; } catch (Exception $e) { // Return an empty anonymous class if there's any error return new class { public function __get($key) { return 'none'; } }; } } }