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/2020_02_06_080530_add_user_permissions.php
<?php

use App\Models\Role;
use App\Models\Rule;
use Illuminate\Database\Migrations\Migration;

class AddUserPermissions extends Migration
{
    protected function updateRules(int $roleID, array $rules, bool $allow)
    {
        foreach ($rules as $object => $actions) {
            foreach ($actions as $action) {
                Rule::updateOrCreate([
                    'role_id' => $roleID,
                    'object'  => $object,
                    'action'  => $action,
                ], ['allow' => $allow]);
            }
        }
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $userRole = Role::where(['name' => 'user'])->first();

        if (isset($userRole)) {
            $allow = [
                'time-intervals' => ['bulk-remove'],
                'tasks' => ['create'],
            ];

            $this->updateRules($userRole->id, $allow, true);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $userRole = Role::where(['name' => 'user'])->first();

        if (isset($userRole)) {
            $disallow = [
                'time-intervals' => ['bulk-remove'],
                'tasks' => ['create'],
            ];

            $this->updateRules($userRole->id, $disallow, false);
        }
    }
}