HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/sigedo-dev.allup.com.co/database/seeds/RolePermissionsTableSeeder.php
<?php

use App\Role;
use App\Permission;
use App\RolePermission;
use Illuminate\Database\Seeder;

class RolePermissionsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $root_permissions = Permission::all();
        Role::findOrFail(1)->permissions()->sync($root_permissions->pluck('id'));
        $roles = Role::where('id', '!=', 1)->orderBy('id', 'asc')->get();

        $listModules = array(
            2 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
            3 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
            4 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
            5 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
            6 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
            7 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
            8 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
            9 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
            10 => array(
                0 => array(
                    0  => 'user',
                    1  => 'userdocument',
                ),
                1 => array(
                    0 => 'edit,show,access',
                    1 => 'create,edit,show,access',
                ),
            ),
        );

        foreach ($root_permissions as $permission) {
            foreach ($roles as $k => $role) {
                foreach ($listModules[$role->id][0] as $key => $module) {
                    if(explode("_", $permission->name)[0] == $module && in_array(explode("_", $permission->name)[1], explode(",", $listModules[$role->id][1][$key]))){
                        RolePermission::create([
                            "permission_id" => $permission->id,
                            "role_id" => $role->id
                        ]);
                    }
                }
            }
        }
    }
}