MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/snap.cafsinfotech.in/database/migrations/2019_01_25_092401_fix_roles.php
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\Models\Rule;
use App\Models\Role;

class FixRoles extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $manager_role_id = 5;
        $blocked_role_id = 255;

        $role_ids = Role::where('id', '<>', $blocked_role_id)
            ->pluck('id')
            ->toArray();

        if (in_array($manager_role_id, $role_ids)) {
            // Allows manager access to the role list, user list.
            $new_manager_rules = [
                ['roles', 'list'],
                ['users', 'manager_access'],
            ];
            foreach ($new_manager_rules as $rule) {
                [$object, $action] = $rule;
                Rule::withTrashed()->updateOrCreate([
                    'role_id' => $manager_role_id,
                    'object' => $object,
                    'action' => $action,
                ], [
                    'allow' => true,
                    'deleted_at' => null,
                ]);
            }
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
    }
}